作业3

class Book1{
private String name;
private int id;
private float price;
private static int num=3;
private static int count=0;
public Book1(){
count++;
this.id=count;
}
public Book1(int id){
this.id=id;
}
public int getId(){
return this.id;
}
public Book1(String name,float price){
this.name=name;
this.price=price;
this.num=num;
}
public void setName(String name){
this.name=name;
}
public String getName(){
return this.name;
}
public void setPrice(float price){
this.price=price;
}
public float getPrice(){
return this.price;
}
public void setNum(int num){
this.num=num;
}
public int getNum(){
return this.num;
}
}
public class sjx06 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Book1 book[]=new Book1[6];
book[0]=new Book1("java教程 ",99.9f);
book[1]=new Book1("java web 教程 ",69.9f);
book[2]=new Book1("java EE 教程 ",67.9f);
book[3]=new Book1("android 教程 ",56.8f);
book[4]=new Book1("Mysql 教程 ",56.5f);
book[5]=new Book1("oracle 教程 ",78.7f);
for(int i=0;i<book.length;i++){
System.out.println("编号:"+new Book1().getId()
+" 书名:"+book[i].getName()
+" 价格:"+book[i].getPrice()
+" 数量:"+book[i].getNum());
}
System.out.println("图书总量为:"+(new Book1().getId()-1)*book[1].getNum());
}
}

原文地址:https://www.cnblogs.com/hell/p/5320229.html