public class Book {
private String bookname,author,press;
private double money;
//通过构造方法实现属性赋值
public Book(String bookname,String author,String press,double money){
this.bookname=bookname;
this.author=author;
this.setpress(press);
this.setmoney(money);
}
/*通过公有的get/set方法实现属性的访问,其中:
1、限定图书价格必须大于10,如果无效需进行提示,并强制赋值为10
2、限定作者、书名均为只读属性
*/
public String getbookname(){
return bookname;
}
public String getauthor(){
return author;
}
public void setpress(String press){
this.press=press;
}
public String getpress(){
return press;
}
public void setmoney(double money){
if(this.money<10){
System.out.println("图书价格最低10元");
money=10;
}
else this.money=money;
}
public double getmoney() {
return money;
}
//信息介绍方法,描述图书所有信息
public void show(){
System.out.println("书名:"+this.getbookname());
System.out.println("作者:"+this.getauthor());
System.out.println("出版社:"+this.getpress());
System.out.println("价格:"+this.getmoney()+"元");
System.out.println("=======================================");
}
}
public class BookText {
Book one=new Book("红楼梦","曹雪芹","人民文学出版社",5);
Book two=new Book("小李飞刀","古龙","中国长安出版社",55.5);
one.show();
two.show();
}
在调用show()方法时出现报错,Syntax error on token "show", Identifier expected after this token