老师,请指导我一下哪里出问题了?
package come.object; public class Book { //私有属性:书名、作者、出版社、价格 private String bname; private String wname; private String cname; private float jname; //通过构造方法实现属性赋值 public Book(String bname,String wname,String cname,float jname){ this.bname=bname; this.wname=wname; this.cname=cname; this.jname=jname; } /*通过公有的get/set方法实现属性的访问,其中: 1、限定图书价格必须大于10,如果无效需进行提示,并强制赋值为10 2、限定作者、书名均为只读属性 */ public String getBname(){ return bname; } private void setBname() { this.bname=bname; } public String getWname(){ return wname; } private void setWname(String Wname){ this.wname=wname; } public String getCname(){ return cname; } public void setCname(String Cname){ this.cname=cname; } public float getJname(){ return jname; } public void setJname(float Jname){ if(jname<10){ this.jname=10; System.out.println("图书价格必须大于10元"); }else{ this.jname=jname; } } //信息介绍方法,描述图书所有信息 public void books(){ System.out.println("书名:"+this.bname); System.out.println("作者:"+this.wname); System.out.println("出版社:"+this.cname); System.out.println("价格:"+this.jname); } }
package come.object; public class BookTest { // 测试方法 public static void main(String[] args) { //实例化对象,调用相关方法实现运行效果 Book one1=new Book(); one1.setBname("红楼梦"); one1.setWname("曹雪芹"); one1.setCname("人民文学出版社"); one1.setJname(10); Book one2=new Book("小李飞刀","古龙","中国长安出版社",55.5f); one2.books(); } }
0
收起
正在回答 回答被采纳积分+1
2回答
藤六
2019-06-18 10:13:04
package come.object; public class BookTest { // 测试方法 public static void main(String[] args) { //实例化对象,调用相关方法实现运行效果 Book one1=new Book(); one1.setBname("红楼梦"); one1.setWname("曹雪芹"); one1.setCname("人民文学出版社"); one1.setJname(10); System.out.println("================"); System.out.println("书名:"+one1.getBname()); System.out.println("作者:"+one1.getWname()); System.out.println("出版社:"+one1.getCname()); System.out.println("价格:"+one1.getJname()); Book one2=new Book("小李飞刀","古龙","中国长安出版社",55.5f); one2.books(); } }
package come.object; public class Book { //私有属性:书名、作者、出版社、价格 private String bname; private String wname; private String cname; private float jname; //通过构造方法实现属性赋值 //通过无参数构造 public Book(){ } //通过带参数构造 public Book(String bname,String wname,String cname,float jname){ //this.bname=bname; //this.wname=wname; //this.cname=cname; //this.jname=jname; this.setBname(bname); this.setWname(wname); this.setCname(cname); this.setJname(jname); } /*通过公有的get/set方法实现属性的访问,其中: 1、限定图书价格必须大于10,如果无效需进行提示,并强制赋值为10 2、限定作者、书名均为只读属性 */ public String getBname(){ return bname; } private void setBname(String bname) { this.bname=bname; } public String getWname(){ return wname; } private void setWname(String Wname){ this.wname=wname; } public String getCname(){ return cname; } public void setCname(String Cname){ this.cname=cname; } public float getJname(){ return jname; } public void setJname(float Jname){ if(jname<10){ this.jname=10; System.out.println("图书价格必须大于10元"); }else{ this.jname=jname; } } //信息介绍方法,描述图书所有信息 public void books(){ System.out.println("书名:"+this.bname); System.out.println("作者:"+this.wname); System.out.println("出版社:"+this.cname); System.out.println("价格:"+this.jname); } }
1. Java 零基础入门
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星