今晚的月色温柔

导航

java--book类

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

    鍥剧墖.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);
        }
}

posted on 2020-10-10 12:17  1022  阅读(486)  评论(0编辑  收藏  举报