设计一个book类,包含图书作者,书名,出版社,单价属性,两个构造方法(一个带参一个不带参

2024-12-31 14:48:25
推荐回答(3个)
回答1:

public class Book {

public Book(){

}

public Book(String author,String bookName,String publishing,Double price){
this.author = author;
this.bookName = bookName;
this.publishing = publishing;
this.price = price;
}

private String author;
private String bookName;
private String publishing;
private Double price;
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getPublishing() {
return publishing;
}
public void setPublishing(String publishing) {
this.publishing = publishing;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public void printBook(){
System.out.print("作者:"+book.getAuthor);
System.out.print("书名:"+book.geBookName);
System.out.print("出版时间:"+book.gePublishing);
System.out.print("单价:"+book.getPrice);
}
public static void main(String[] args) {

Book book = new Book("AAA","J2EE","清华出版社",28);
book.printBook();

}
}

回答2:

public class Book {

public Book(){

}

public Book(String author,String bookName,String publishing,Double price){
this.author = author;
this.bookName = bookName;
this.publishing = publishing;
this.price = price;
}

private String author;
private String bookName;
private String publishing;
private Double price;
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getPublishing() {
return publishing;
}
public void setPublishing(String publishing) {
this.publishing = publishing;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}

public String printBook(){

return "book message: [author = "+author+"],[bookName = "+bookName+"],[publishing = "+publishing+"],[price = "+price+"]";
}

public static void main(String[] args) {

Book book1 = new Book();
String bookmsg1 = book1.printBook();
System.out.println(bookmsg1);

Book book2 = new Book("someone","Java","someplace",new Double(30));
String bookmsg2 = book2.printBook();
System.out.println(bookmsg2);

}
}

回答3:

这些东西还是自己写的好!