Java题求解: 设计一个表示图书的book类,它包含图书的作者、书名、书号、月销售量属性,另有两
Java题求解:设计一个表示图书的book类,它包含图书的作者、书名、书号、月销售量属性,另有两个构造方法(一个带参数,一个不带参数),有一个成员方法printBook(...
Java题求解: 设计一个表示图书的book类,它包含图书的作者、书名、书号、月销售量属性,另有两个构造方法(一个带参数,一个不带参数),有一个成员方法printBook()用于输出数据。设置一测试类测试并输出。
展开
2个回答
展开全部
//它包含图书的作者、书名、书号、月销售量属性,
//另有两个构造方法(一个带参数,一个不带参数),
//有一个成员方法printBook()用于输出数据。设置一测试类测试并输出。
public class Book {
private String author;
private String title;
private String num;
private int sale;
public Book(){}
public Book(String auther, String title, String num, int sale){
this.author = auther;
this.title = title;
this.num = num;
this.sale = sale;
}
public void printBook(){
System.out.println("author:" + author + ", title:" + title + ", num:" + num + ", sale:"+sale);
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public int getSale() {
return sale;
}
public void setSale(int sale) {
this.sale = sale;
}
}
测试类:
public static void main(String[] args) {
Book b = new Book("author","title","123456798",1000);
b.printBook();
}
//另有两个构造方法(一个带参数,一个不带参数),
//有一个成员方法printBook()用于输出数据。设置一测试类测试并输出。
public class Book {
private String author;
private String title;
private String num;
private int sale;
public Book(){}
public Book(String auther, String title, String num, int sale){
this.author = auther;
this.title = title;
this.num = num;
this.sale = sale;
}
public void printBook(){
System.out.println("author:" + author + ", title:" + title + ", num:" + num + ", sale:"+sale);
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public int getSale() {
return sale;
}
public void setSale(int sale) {
this.sale = sale;
}
}
测试类:
public static void main(String[] args) {
Book b = new Book("author","title","123456798",1000);
b.printBook();
}
展开全部
package com.yutu.test;
public class Book {
private String author;
private String bookName;
private int bookNum;
private int total;
public Book(){}
public Book(String author, String bookName, int bookNum, int total) {
super();
this.author = author;
this.bookName = bookName;
this.bookNum = bookNum;
this.total = total;
}
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 int getBookNum() {
return bookNum;
}
public void setBookNum(int bookNum) {
this.bookNum = bookNum;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
/**输出信息*/
public void printBook(){
System.out.println("作者:"+author+"-书名:"+bookName+"-书号:"+bookNum+"-销售量:"+total);
}
}
package com.yutu.test;
public class TestBook {
public static void main(String[] args) {
Book book=new Book();
book.setAuthor("莫言");
book.setBookName("我不想说");
book.setBookNum(147);
book.setTotal(1234);
book.printBook();
Book book1=new Book("金庸", "倚天屠龙记", 12346, 20000);
book1.printBook();
}
}
作者:莫言-书名:我不想说-书号:147-销售量:1234
作者:金庸-书名:倚天屠龙记-书号:12346-销售量:20000
public class Book {
private String author;
private String bookName;
private int bookNum;
private int total;
public Book(){}
public Book(String author, String bookName, int bookNum, int total) {
super();
this.author = author;
this.bookName = bookName;
this.bookNum = bookNum;
this.total = total;
}
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 int getBookNum() {
return bookNum;
}
public void setBookNum(int bookNum) {
this.bookNum = bookNum;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
/**输出信息*/
public void printBook(){
System.out.println("作者:"+author+"-书名:"+bookName+"-书号:"+bookNum+"-销售量:"+total);
}
}
package com.yutu.test;
public class TestBook {
public static void main(String[] args) {
Book book=new Book();
book.setAuthor("莫言");
book.setBookName("我不想说");
book.setBookNum(147);
book.setTotal(1234);
book.printBook();
Book book1=new Book("金庸", "倚天屠龙记", 12346, 20000);
book1.printBook();
}
}
作者:莫言-书名:我不想说-书号:147-销售量:1234
作者:金庸-书名:倚天屠龙记-书号:12346-销售量:20000
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询