一个java问题,请教高手

2024-12-13 04:42:27
推荐回答(4个)
回答1:

这个代码你可以参考一下
public class Book {
private String bookName;
private static String bookNO;
private static int bookCount;
private float price;
public Book(){
bookCount++;
this.bookNO = "000"+bookCount;
}
public Book(String bookName,float price){
this.bookName = bookName;
this.price = price;
bookCount++;
this.bookNO = "000"+bookCount;
}
public static void main(String[] args) {
Book[] book = new Book[10];
for (int i = 0; i < book.length; i++) {
book[i] = new Book();
}
System.out.println(bookNO);
System.out.println("总册数:"+bookCount);
}

public static int getBookCount() {
return bookCount;
}
public static void setBookCount(int bookCount) {
Book.bookCount = bookCount;
}
public static String getBookNO() {
return bookNO;
}
public static void setBookNO(String bookNO) {
Book.bookNO = bookNO;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}

回答2:

你是 初学者吧 这其实挺简单的 你只要把涉及到的定义都弄明白 就很好编了
劝你还是不要求源代码 哪不会你可以问我 我给你讲讲思路 概念
自己不思考永远不会进步的

回答3:

的却,去看看书,里面这种例子多的是,模仿这先写,然后慢慢搞懂

回答4:

慢慢学吧,真正变成比这复杂多了