改正代码中的错误package ke; public class Books1 { //成员变量 int id; String name; //图书名称 double price; //图书单价 int number; //图书数量 double money; //总价 String publish; //出版社 //构造方法 public Books1(int id, String name, double price, int number, double money, String publish) { super(); this.id = id; this.name = name; this.price = price; this.number = number; this.money = money; this.publish = publish; } @Override public String toString() { String message = "图书编号:" + id + " 图书名称:" + name + " 出版社:" + publish + " 单价:" + price + " 库存数量:" + number; return message; } public void setNumber(int number) { this.number = number; } }
时间: 2024-02-14 07:08:59 浏览: 72
jsp struts1 标签实例详解第1/2页
代码中的错误是缺少了包的声明语句,应该在代码开头添加以下语句:
```
package ke;
```
添加后的完整代码如下:
```
package ke;
public class Books1 {
//成员变量
int id;
String name; //图书名称
double price; //图书单价
int number; //图书数量
double money; //总价
String publish; //出版社
//构造方法
public Books1(int id, String name, double price, int number, double money, String publish) {
super();
this.id = id;
this.name = name;
this.price = price;
this.number = number;
this.money = money;
this.publish = publish;
}
@Override
public String toString() {
String message = "图书编号:" + id + " 图书名称:" + name + " 出版社:" + publish + " 单价:" + price + " 库存数量:" + number;
return message;
}
public void setNumber(int number) {
this.number = number;
}
}
```
阅读全文