1. 程式人生 > 其它 >利用poi修改excel模板內容並下載

利用poi修改excel模板內容並下載

· 前言:

         1.題目集四前言

  本次題目共分3到練習題,分別考察判斷、迴圈、陣列的建立、運用,加強了我對陣列中資料的應用、查詢、判斷,題目集一的難度相對比較簡單一些,非是困難程度,題目集一是側重於對基礎知識點的掌握,加強了我的java基礎。加強了我對呼叫資料的應用,學會了如何在文字中提出數字,並進行計算,排序。座標的輸入,讀取,計算,判斷最終出值與輸出的關係。學會(靜態、公有方法),存款,取款等操作。

        2.期中考試

學會了建立多類,本次3題的難度大於題目集一題目的難度,其中知識的考查包括題目集一知識,多些為陣列中轉化的運用,指定陣列輸出,判斷指定輸出,內容判斷,內容提取等等,練習程式多種運用寫法,加強運用性,本次題目集的重點為第二題,本題目的難度略大於其他題目難度,起初並不知道如何去寫,在書上學習和上網查詢後也掌握了後瞭解怎樣進行程式設計,考察了我們對於字串陣列,以及字串.length()方法的用法,相對簡單,本次題目加強了我對java的多方面運用,對java用法更靈活。

      3.期中考試

本次題目集的難度高於前兩次的題目集難度,考察座標的輸入問題,對資料中陣列的讀取,第一題的難度主要為點與點之間距離計算,與輸入"+,-"的座標判斷並能否執行,解決後其他難度就降低了,第二,第三題的主要問題和第一題基本一樣,判斷不同,為點線距離問題,三角形判斷問題,考察多型性以及使用方法,本題目集的第二,第三題的難度相對第一題難度有所提高,主要考察我們對所建立的使用與呼叫問題。

    4期中考試

第三題原型與第一、二題的基礎,並加強難度,改變程式碼,在“點與線(繼承與多型)”題目基礎上,增加容器類儲存點、線、面對象,並對該容器進行相應增、刪、遍歷操作。此題的難度在於如何建立容器,在容器中建立各個物件,主要考察我們繼承與多型,此題難度高於前兩道題,略顯困難。

·讓我對類的聚合關係理解更加深刻,還有類的繼承和多型,本次考察主要向我們滲透了一些關於Java的設計原則,讓我們能更加深刻的思考類與類之間的關係,從而深入的瞭解面向物件的設計原則,這些都是這四次習題集考察的亮點。

· 設計與分析:

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true) {
            String a=sc.nextLine();
            
if(a.equals("end")) break; String[] split=a.split("\\D+"); int i; long sum = 0; for(i=0;i<split.length;i++){ if(!split[i].equals("")) { int digit=Integer.parseInt(split[i]); sum+=digit; } } System.out.println(sum); } } }

本程式碼為題目集四7-1,主考察我們文字中提取數字,並進行運算,其中主要運用正則表示式,通過本次題目我瞭解並學會了正則表示式,正則表示式是解決此題的關鍵,依賴性也較大,使類與類之間的聯絡更緊切,此題大部分運用陣列並對陣列中資料的查詢,陣列的儲存,中字串的呼叫,輸出等等。

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    Double x1 = sc.nextDouble();
    Double y1 = sc.nextDouble();
    Double x2 = sc.nextDouble();
    Double y2 = sc.nextDouble();
    String color = sc.next();
    Point point1 = new Point(x1, y1);
    Point point2 = new Point(x1, y2);
    Line line = new Line(point1,point2,color);
       if(x1<=0||x1>200||x2<=0||x2>200||y1<=0||y1>200||y2<=0||y2>200)
       {
           System.out.println("Wrong Format");
       }
       else
       {   
        Main point = null;
        line.display();
       }
    }

    private String getcolor;
    private Point point2;
    private Object point1;
    
       public void display() {
           System.out.println("The line's color is:"+this.getcolor);
                System.out.println("The line's begin point's Coordinate is:"+String.format("%.2f", ((Point) this.point1).getX())+","+String.format("%.2f",((Point) this.point1).getY()));
                System.out.println("The line's end point's Coordinate is:"+String.format("%.2f",((Point) this.point2).getX())+","+String.format("%.2f",((Point) this.point2).getY()));
                System.out.println("The line's length is:"+Math.sqrt((((Point) point1).getX()-point2.getX())*(((Point) point1).getX()-point2.getX())+(((Point) point1).getY()-point2.getY())*(((Point) point1).getY()-point2.getY())));
       }
       }
class Line{
     Point point1;
     Point point2;
     String color;
     public Line(Point p1,Point p2,String color) {
         this.point1 = p1;
         this.point2 = p2;
         this.color = color;
     }
     public Point getPoint1(){
         return point1;
     }
    public void setPoint1(Point point1){
        this.point1 = point1;
     }
    public Point getPoint2(){
        return point2;
     }
    public void setPoint2(Point point2){
        this.point2 = point2;
     }
    public String getColor(){
        return color;
     }
    public void setColor(String color){
        this.color = color;
     }
    public double getDistance(){
        return Math.sqrt((point1.getX()-point2.getX())*(point1.getX()-point2.getX())+(point1.getY()-point2.getY())*(point1.getY()-point2.getY()));
    }
    public void display() {
      
    }
} 
class Point {
    double x;
    double y;// x,y為點的座標
    private Object point1;
    private Point point2;
    //求兩點之間的距離
    public Point(double x,double y) {
       
        this.x = x;
        this.y = y;
    }
    public double getX() {
        return x;
    }
    public void setX(double x) {
        this.x = x;
    }
    public double getY() {
        return y;
    }
    public void setY(double y) {
        this.y = y;
    }
    public void display() {
        
    }
    }

此題為期中考試第一題,主考察類設計,建立多個類,執行多個類,其中有對顏色的輸入,對相對顏色的輸出,輸入橫座標、縱座標、終點的橫座標、縱座標,判斷兩點之間的距離,輸出長度值,這就是本題考查的重點。

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    Double x1 = sc.nextDouble();
    Double y1 = sc.nextDouble();
    Double x2 = sc.nextDouble();
    Double y2 = sc.nextDouble();
    String color = sc.next();
    Point point1 = new Point(x1, y1);
    Point point2 = new Point(x1, y2);
    Line line = new Line(point1,point2,color);
       if(x1<=0||x1>200||x2<=0||x2>200||y1<=0||y1>200||y2<=0||y2>200)
       {
           System.out.println("Wrong Format");
       }
       else
       {   
        Main point = null;
        line.display();
       }
    }

    private String getcolor;
    private Point point2;
    private Object point1;
    
       public void display() {
           System.out.println("The line's color is:"+this.getcolor);
                System.out.println("The line's begin point's Coordinate is:"+String.format("%.2f", ((Point) this.point1).getX())+","+String.format("%.2f",((Point) this.point1).getY()));
                System.out.println("The line's end point's Coordinate is:"+String.format("%.2f",((Point) this.point2).getX())+","+String.format("%.2f",((Point) this.point2).getY()));
                System.out.println("The line's length is:"+Math.sqrt((((Point) point1).getX()-point2.getX())*(((Point) point1).getX()-point2.getX())+(((Point) point1).getY()-point2.getY())*(((Point) point1).getY()-point2.getY())));
       }
       }
class Line{
     Point point1;
     Point point2;
     String color;
     public Line(Point p1,Point p2,String color) {
         this.point1 = p1;
         this.point2 = p2;
         this.color = color;
     }
     public Point getPoint1(){
         return point1;
     }
    public void setPoint1(Point point1){
        this.point1 = point1;
     }
    public Point getPoint2(){
        return point2;
     }
    public void setPoint2(Point point2){
        this.point2 = point2;
     }
    public String getColor(){
        return color;
     }
    public void setColor(String color){
        this.color = color;
     }
    public double getDistance(){
        return Math.sqrt((point1.getX()-point2.getX())*(point1.getX()-point2.getX())+(point1.getY()-point2.getY())*(point1.getY()-point2.getY()));
    }
    public void display() {
      
    }
} 
class Point {
    double x;
    double y;// x,y為點的座標
    private Object point1;
    private Point point2;
    //求兩點之間的距離
    public Point(double x,double y) {
       
        this.x = x;
        this.y = y;
    }
    public double getX() {
        return x;
    }
    public void setX(double x) {
        this.x = x;
    }
    public double getY() {
        return y;
    }
    public void setY(double y) {
        this.y = y;
    }
    public void display() {
        
    }
    }

此題為期中考試第二題,此題主考察繼承與多型,在第一題的基礎上改進,基礎也是建立多種類,在類的基礎上進行繼承與多型,此題輸出與第一題相似,也是輸出顏色,計算輸出距離,輸出顏色,以實現繼承與多型的技術性需求。

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    Double x1 = sc.nextDouble();
    Double y1 = sc.nextDouble();
    Double x2 = sc.nextDouble();
    Double y2 = sc.nextDouble();
    String color = sc.next();
    Point point1 = new Point(x1, y1);
    Point point2 = new Point(x1, y2);
    Line line = new Line(point1,point2,color);
       if(x1<=0||x1>200||x2<=0||x2>200||y1<=0||y1>200||y2<=0||y2>200)
       {
           System.out.println("Wrong Format");
       }
       else
       {   
        Main point = null;
        line.display();
       }
    }

    private String getcolor;
    private Point point2;
    private Object point1;
    
       public void display() {
           System.out.println("The line's color is:"+this.getcolor);
                System.out.println("The line's begin point's Coordinate is:"+String.format("%.2f", ((Point) this.point1).getX())+","+String.format("%.2f",((Point) this.point1).getY()));
                System.out.println("The line's end point's Coordinate is:"+String.format("%.2f",((Point) this.point2).getX())+","+String.format("%.2f",((Point) this.point2).getY()));
                System.out.println("The line's length is:"+Math.sqrt((((Point) point1).getX()-point2.getX())*(((Point) point1).getX()-point2.getX())+(((Point) point1).getY()-point2.getY())*(((Point) point1).getY()-point2.getY())));
       }
       }

本題為期中考試第三題,此題建立在第一、二題的基礎上。此題因為時間問題和知識運用不夠熟練,並沒在pta聯絡中提交,有後餘時間將其完成。本題考察點與線間的距離運算問題,本題目與數學結合,難度為輸入數字正確進入相應判斷執行公式中,正確輸出,建立不同的資料型別,呼叫建立函式,進入計算執行,其他問題為情況不符合情況,判斷問題的否定輸出等等。本題出現多次Blog,多次看書,在網上查詢學習資料,學習,瞭解,最後進行程式設計。

下面是我從網上尋找的降低圈複雜度的方法,在今後的學習或者在解決PTA題目時會學著慢慢的滲透和嘗試降低圈複雜度的方法。

•Simplifying Conditional Expressions(簡化條件表示式)

Decompose Conditional(分解條件式)

Consolidate Conditional Expression(合併條件式)

Consolidate Duplicate Conditional Fragments(合併重複的條件片斷)

  • 採坑心得
  • 在設計類時,圈複雜度較大,在今後我將學習如何將圈複雜度降低。
  • 考試的第一題我沒有全面的考慮好,導致沒有滿分,在一方面的考點沒有兼顧到導致
  • 只得了16分,下次改進。


  • 3.類與類之關係,以及怎樣更好的減少類與類之間的關係,在設計程式碼時,我設計的兩個類總是有很多的關聯,子類繼承父類的功能,這些關係我在解題時依然不清楚。

    4.多道練習的訓練,是我對類建立的應用,字串,迴圈大大熟練,更好的進行陣列和字串,類的運用

  • class Line{
         Point point1;
         Point point2;
         String color;
         public Line(Point p1,Point p2,String color) {
             this.point1 = p1;
             this.point2 = p2;
             this.color = color;
         }
         public Point getPoint1(){
             return point1;
         }
        public void setPoint1(Point point1){
            this.point1 = point1;
         }
        public Point getPoint2(){
            return point2;
         }
        public void setPoint2(Point point2){
            this.point2 = point2;
         }
        public String getColor(){
            return color;
         }
        public void setColor(String color){
            this.color = color;
         }
        public double getDistance(){
            return Math.sqrt((point1.getX()-point2.getX())*(point1.getX()-point2.getX())+(point1.getY()-point2.getY())*(point1.getY()-point2.getY()));
        }
        public void display() {
          
        }
    } 
    class Point {
        double x;
        double y;// x,y為點的座標
        private Object point1;
        private Point point2;
        //求兩點之間的距離
        public Point(double x,double y) {
           
            this.x = x;
            this.y = y;
        }
        public double getX() {
            return x;
        }
        public void setX(double x) {
            this.x = x;
        }
        public double getY() {
            return y;
        }
        public void setY(double y) {
            this.y = y;
        }
        public void display() {
            
        }
        }
    • 總結

    1.通過三次的習題集,尤其是題目1(7-4)、題目集3(7-2)這兩個題在關於類設計的時候,設計到的程式設計原則,實現同樣的功能,類的設計卻有好幾種可能,怎樣使類的設計更加的合理,能大大的提高我們程式碼的質量。

    2.我應多在類方面下功夫,我認為類是可以很好的避免不同的錯誤。

    3.部分框架的使用比c語言陣列要簡單,運用的更容易,可以幫我們減少很多錯誤,減少我們在修改時浪費的時間,在今後的設計中,自己要學習使用這些方便的集合框架的,使程式碼更加的簡潔、方便,且實現功能。

    4.希望老師能夠給更多的時間來完成作業,題目的難度希望是逐漸加深,不是一個題目集中都是很難的題目。

    5這三次的習題集,又進一步的提升了我的程式設計能力,初步形成了面向物件設計的思想,以及類與類之間的關係都得到了一定程度的掌握,這三次習題集的有一定的收穫。