设置了价格限制 但没用 求老师指导
public class Book { private String Bname; private String name; private float n; private String press; public float getN() { return n; } public void setN(float n) { if(n<=10) System.out.println("图书的价格必须大于10元!"); else this.n = n; } public String getPress() { return press; } public void setPress(String press) { this.press = press; } public String getBname() { return Bname; } public String getName() { return name; } public void bookmath(String Bname,String name,float n,String press) { System.out.println("书名:"+Bname); System.out.println("作者:"+name); System.out.println("出版社:"+press); System.out.println("价格:"+n+"元"); } } public class BookTest { public static void main(String[] args) { Book math1 = new Book(); math1.bookmath("红楼梦"," 曹雪芹", 1f, "人名文学出版社"); System.out.println("========================="); Book math2 = new Book(); math2.bookmath("小李飞刀"," 古龙", 55.5f, "中国长安出版社"); } }
17
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星