改正代码中的错误package ke; public class RecordBooksOrder { //成员变量 int id; String name; //图书名称 double price; //图书单价 int number; //图书数量 double money; //总价 String publish; //出版社 //构造方法 public Books(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-03-05 08:53:28 浏览: 58
Shell执行/调用Java/Jar程序例子的实例详解
代码中存在一个错误,类名不匹配。应该将类名从 `RecordBooksOrder` 改为 `Books`。修改后的代码如下:
```java
package ke;
public class Books {
//成员变量
int id;
String name; //图书名称
double price; //图书单价
int number; //图书数量
double money; //总价
String publish; //出版社
//构造方法
public Books(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;
}
}
```
请注意,修改后的类名应该与文件名相同,即应该将文件名也改为 `Books.java`。
阅读全文