我从书中重新输入了这些代码,以某种方式我得到了错误“找不到符号-类InventoryItem”
detach
我是Java新手,请帮忙 谢谢。
答案 0 :(得分:0)
您当前所在的班级找不到班级(符号)InventoryItem
。您需要定义此类和getData方法。
public class InventoryItem{
private String desc;
private int units;
public InventoryItem(){
Scanner keyboard = new Scanner(System.in);
System.out.print("enter descri: ");
desc = keyboard.nextLine();
System.out.print("number of unit: ");
units = keyboard.nextInt();
}
public static InventoryItem getData() {
return this;
}
}
答案 1 :(得分:0)
我认为这应该是您需要的InventoryItem
。
/**
* This class uses three constructors.
*/
public class InventoryItem {
private String description; // Item description
private int units; // Units on-hand
/**
* No-arg constructor
*/
public InventoryItem() {
description = "";
units = 0;
}
/**
* The following constructor accepts a
* String argument that is assigned to the
* description field.
*/
public InventoryItem(String d) {
description = d;
units = 0;
}
/**
* The following constructor accepts a
* String argument that is assigned to the
* description field, and an int argument
* that is assigned to the units field.
*/
public InventoryItem(String d, int u) {
description = d;
units = u;
}
/**
* The setDescription method assigns its
* argument to the description field.
*/
public void setDescription(String d) {
description = d;
}
/**
* The setUnits method assigns its argument
* to the units field.
*/
public void setUnits(int u) {
units = u;
}
/**
* The getDescription method returns the
* value in the description field.
*/
public String getDescription() {
return description;
}
/**
* The getUnits method returns the value in
* the units field.
*/
public int getUnits() {
return units;
}
}
答案 2 :(得分:0)
也许是您的InventoryItem
班级:
public class InventoryItem {
private String desc;
private int units;
public InventoryItem(String desc, int units) {
this.desc=desc;
this.units=units;
}
public String getDescription() {
return desc;
}
public int Units() {
return units;
}
}