代码如下,请老师检阅一下,是否有需要修改的地方
package com.imooc.object; public class Book { private String title; private String author; private String press; private double price; private double lowestPrice = 10; public Book(String title,String author,String press,double price) { this.title = title; this.author = author; this.setPress(press); this.setPrice(price); } public void introduction() { System.out.println("书名:" + this.getTitle()); System.out.println("作者:" + this.getAuthor()); System.out.println("出版社:" + this.getPress()); System.out.println("价格:" + this.getPrice() + "元"); } public String getPress() { return press; } public void setPress(String press) { this.press = press; } public double getPrice() { return price; } public void setPrice(double price) { if(price <= 10) { System.out.println("书的最低价格不得低于10元"); this.price = lowestPrice; }else { this.price = price; } } public String getTitle() { return title; } public String getAuthor() { return author; } }
public class BookTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Book one = new Book("红楼梦","曹雪芹","人民文学出版社",5);
one.introduction();
System.out.println("===============================");
Book two = new Book("小李飞刀","古龙","中国长安出版社",55.5);
two.introduction();
}
}
66
收起
正在回答 回答被采纳积分+1
2回答
chrismorgen
2018-04-19 10:04:50
同学完成的不错,继续加油,祝学习愉快!
Java零基础入门18
- 参与学习 人
- 提交作业 7317 份
- 解答问题 14452 个
想要入门学编程?多年一直活跃在编程语言排行版前列的Java是一个很好的选择。本路径将从Java基础语法、面向对象、常用工具类三部分,为你开启软件开发的大门!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星