2016701010126 2016-2071-2 《java程序設計》一至四章總結

        這是課堂的最後一個編程題,我課堂上這樣寫: 編程

package book;學習

public class Book {
    public static void main(String[] args)
    {
     Books[] books=new Books[3];
     
     books[0]=new Books("Java程序設計",119.00);
     books[1]=new Books("C語言程序設計",72.50);
     books[2]=new Books("Python程序設計",35.85);
     
     for(Books e:books){
      e.setId();
      System.out.println("書名:"+e.getName()+",書號:"+e.getId()
      +",書價:"+e.getPrice());
     }
     int n=Books.getNextID();
     System.out.println(n);
    }
}
package books;this

public class Books {
 private static int nextId=0;
 
 private String name;
 private int id;
 private double price;
 
 public Books(String n,double p)
 {
  name=n;
  id=0;
  price=p;
 }
 
 public String getName(){
  return name;
 }
 public int getId(){
  return id;
 }
 public double getPrice(){
  return price;
 }
 public void setId(){
  nextId++;
  id=nextId;
 }
 public static int getNextID(){
  return nextID;
 }設計

}get

接下來是我修改後的,我以爲這個還行,請幫忙檢查修改一下程序設計

package book;class

public class Book {
    public static void main(String[] args)
    {
     Books[] books=new Books[3];
     
     books[0]=new Books("Java程序設計",119.00f,3);
     //實數默認爲double,float型實數後應該加f/F;
     books[1]=new Books("C語言程序設計",72.50f,8);
     books[2]=new Books("Python程序設計",35.85f,5);
     
     for(Books e:books){
      e.setId();
      System.out.println("書名:"+e.getName()+",書號:"+e.getId()
      +",書價:"+e.getPrice()+",書冊:"+e.getCount());
     }
     int n=Books.getSumcount();
     System.out.println("圖書總數:"+n);
    }
}
package book;float

public class Books {
 private static int nextId=0;
 
 private String name;
 private int id;
 private float price;程序

 private int count;
 private static int sumcount=0;
 
 public Books(String name,float price,int count)  
 //(String n,double p)
 {
  /*name=n;
  id=0;
  price=p;*/
  this.name=name;
  this.id=0;
  this.price=price;
  this.count=count;
 }
 
 public String getName(){
  return name;
 }
 public int getId(){
  return id;
 }
 public float getPrice(){
  return price;
 }
 public int getCount(){
  return count;
 }
 public void setId(){
  nextId++;
  id=nextId;
  sumcount+=id*count;
 }
 public static int getSumcount(){
  return sumcount;
 }next

}

     經過此次測驗,我知道了我自認爲對前四章很瞭解的內容仍是不熟悉,我應該在學習後面的課程的同時複習前面的知識,不能以爲本身已經掌握了就不看了。

相關文章
相關標籤/搜索