java book类_java–book类

  • Post author:
  • Post category:java


根据下列类图,设计Book类:

1570782365942013054.png

【输入形式】

【输出形式】

(default, noname, 50.0)

(java, lixinghua, 89.9)

(java, ligang, 101.8)

【样例输入】

【样例输出】

【样例说明】

【评分标准】

class  Book{

private String title,author;

private double price;

public Book(){

this.title=”default”;

this.author=”noname”;

this.price=50.0;

}

public Book(String title,String author,double price){

this.title=title;

this.author=author;

this.price=price;

}

public String getTitle(){

return this.title;

}

public void setTitle(String title){

this.title=title;

}

public String getAuthor(){

return this.author;

}

public void setAuthor(String author){

this.author=author;

}

public double getPrice(){

return this.price;

}

public void setPrice(double price){

this.price=price;

}

public String toString(){

return “(“+this.title+”, “+this.author+”, “+this.price+”)”;

}

}

public  class  BookApp  {

public  static  void  main(String[]  args)  {

Book  book1=new  Book();

Book  book2=new  Book(“java”,”lixinghua”,89.9);

System.out.println(book1);

System.out.println(book2);

book1.setAuthor(“ligang”);

book1.setTitle(“java”);

book1.setPrice(101.8);

System.out.println(book1);

}

}



版权声明:本文为weixin_42509796原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。