我试图在学校做一个项目,我创建自己的对象,以及私人数据,方法等。这不是一个带有用户界面的完整工作系统;它只是创建类的机会,然后实例化并测试它们。
Dina's Dinettes项目中的虚构业务,销售一种餐桌椅套装。订单包括一个表,零到十个椅子,以及零到两个叶子。客户还可获得一件免费物品,包括:(1)清洁套件,(2)座垫,或(3)桌椅垫。您要编写的代码是系统的开始,用于创建和处理订单以及维护商店库存。
我遇到的一个问题是我试图设置"选项"设置被假定为枚举类型。我以为我可以将枚举值设置为私有数据以及orderNumber,chairCount和leafCount值,但我得到了很多"找不到符号"错误。这是我到目前为止所做的:
public class DinetteOrder
{
//---------------------------------------------------------------------------
// STATIC CONSTANTS
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// PRIVATE INSTANCE DATA
//---------------------------------------------------------------------------
private int orderNumber;
private int chairCount;
private int leafCount;
private enum option {cleanKit, seatCush, padFeet};
//---------------------------------------------------------------------------
// CONSTRUCTORS
//---------------------------------------------------------------------------
public DinetteOrder(){
orderNumber = 0;
chairCount = 0;
leafCount = 0;
option = 0;
}
public DinetteOrder(int orderNumber, int chairCount, int leafCount, option option){
this.orderNumber = orderNumber;
this.chairCount = chairCount;
this.leafCount = leafCount;
this.option = option;
}
//---------------------------------------------------------------------------
// ASSESSORS
//---------------------------------------------------------------------------
public int orderNumer(){
return orderNumber;
}
public int getChairCount(){
return chairCount;
}
public int getLeafCount(){
return leafCount;
}
public option getOption(){
return option;
}
//---------------------------------------------------------------------------
// MUTATORS
//---------------------------------------------------------------------------
public void setChairCount(int chairCount) {
this.chairCount = chairCount;
}
public void setLeafCount(int leafCount) {
this.leafCount = leafCount;
}
public void setOption(Option option) {
this.option = Option;
}
//---------------------------------------------------------------------------
// OTHER METHODS
//---------------------------------------------------------------------------
public double getPrice(int DinetteOrder) {
double getPrice = 219.00 + (59.00 * chairCount) + (35.00 * leafCount);
return getPrice;
}
public String toString(){
return "Table Count: 1\n Chair Count: " + chairCount + "\n Leaf Count: " + leafCount + "\n";
}
}
对于我做错了什么的任何输入都将不胜感激。
答案 0 :(得分:4)
您已定义option
枚举,但未定义option
实例变量。
此:
private enum option {cleanKit, seatCush, padFeet};
应该变成:
public enum Option {cleanKit, seatCush, padFeet};
private Option option;
你的构造函数改为:
public DinetteOrder(int orderNumber, int chairCount, int leafCount, Option option) {
this.orderNumber = orderNumber;
this.chairCount = chairCount;
this.leafCount = leafCount;
this.option = option;
}
请注意,对于枚举类型使用大写“O”,对于实例变量和构造函数参数名称使用小“o”。此外,您的第一个构造函数无法将0
指定为option
;它需要是枚举值之一。