设置枚举类型的问题 [英] Problems with setting up an enum type

查看:102
本文介绍了设置枚举类型的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从我正在创建自己的对象的学校做一个项目,以及私人数据,方法等。这不是一个具有用户界面的完整的工作系统;这只是一个创建课程,然后实例化和测试他们的机会。

I'm trying to do a project from school in which I'm creating my own objects, along with private data, methods, etc. This isn’t a complete working system with a user interface; it’s just a chance to create classes, then instantiate and test them.

项目中的虚构业务Dina的Dinettes正在销售一种dinette集。一个订单包括一张桌子,零到十把椅子,零到两张。客户还可以订购一个免费物品,(1)清洁套件,(2)座垫,或(3)桌子和椅子的垫脚。您要编写的代码是创建和处理订单的系统的开始,并维护商店库存。

The fictional business in the project Dina’s Dinettes who is selling one type of dinette set. An order consists of one table, zero to ten chairs, and zero to two leaves. The customer also gets one free item with their order, either (1) a cleaning kit, (2) seat cushions, or (3) padded feet for the table and chairs. The code you’ll write is the start of a system to create and process orders, and maintain store inventories.

我遇到的一个问题是我正在尝试设置假定为枚举类型的选项设置。我以为我可以将枚举值设置为私有数据以及orderNumber,chairCount和leafCount值,但是我收到了很多找不到符号的错误。这是我迄今为止所做的:

One issue I'm having is I'm trying to set up the "option" setting which is assumed to be a enum type. I thought I could set up the enum value as private data along with the orderNumber, chairCount, and leafCount values, but I'm getting a lot of "cannot find symbol" errors. Here is what I've done so far:

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";
    }

}

推荐答案

您已经定义了一个选项枚举但不是一个选项实例变量。

You've defined an option enum but not an option instance variable.

这样:

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 分配为选项;它将需要是枚举值之一。

Note the use of capital "O" for the enum type and small "o" for the instance variable and constructor parameter name. Additionally, your first constructor cannot assign 0 as the option; it will need to be one of the enum values.

这篇关于设置枚举类型的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆