如何从访问器导入私有枚举类型 [英] How to import an private enum type from a accessor

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

问题描述

我不确定问题的标题是否合适,但是这里:

I am not sure that the title of the question is appropriate, but here goes:

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

I'm doing 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.

我遇到的问题是使用一个名为SubmitOrder的方法在DinetteStore类中。我正在尝试导入一个名为Option(一个给你免费的项目来绑定Dinette订单)的枚举类型到方法,我得到找不到符号错误。我以为这样做就像内置的类型一样简单,但是它不会这样工作。为了增加皱纹,我已经将枚举类型设为私有,我不知道是否可以这样做。我想知道我是否应该从DinetteOrder类导入一些东西。任何帮助将不胜感激。

The issue I'm having is with a method called submitOrder that made within the DinetteStore class. I'm trying to import an enum type called Option (The one that gives you the free items to bind with the Dinette Order) into the method and I'm getting the "Cannot find symbol" error. I thought it would be simple to do like the built-in types, but it's not working that way. To add to the wrinkle, I've made the enum type private and I don't know if I can do that. I'm wondering if I should import something from the DinetteOrder class. Any help would be appreciated.

public class DinetteOrder
{
   //---------------------------------------------------------------------------
   //      STATIC CONSTANTS
   //---------------------------------------------------------------------------
   **public enum Option {cleanKit, seatCush, padFeet};**


   //---------------------------------------------------------------------------
   //      PRIVATE INSTANCE DATA
   //---------------------------------------------------------------------------
   private int orderNumber;
   private int chairCount;
   private int leafCount;
   private Option option;

   //---------------------------------------------------------------------------
   //      CONSTRUCTORS
   //---------------------------------------------------------------------------

   public DinetteOrder(){
       orderNumber = 0;
       chairCount = 0;
       leafCount = 0;
       option = null;
   }

   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 getOrderNumber(){
       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 "Order Number: " + orderNumber + "1\n Chair Count: " + chairCount + "\n Leaf Count: " + leafCount + "\n";
    }

}

public class DinetteStore
{
   //---------------------------------------------------------------------------
    //      PRIVATE INSTANCE DATA
   //---------------------------------------------------------------------------
   private int tableInventory;
   private int chairInventory;
   private int leafInventory;
   private double totalSales;
   private int numSales;

   //public enum Option {cleanKit, seatCush, padFeet};


   public DinetteStore(){
       tableInventory = 0;
       chairInventory = 0;
       leafInventory = 0;
   }

   //---------------------------------------------------------------------------
   //      CONSTRUCTORS
   //---------------------------------------------------------------------------

   public DinetteStore(int tableInventory, int chairInventory, int leafInventory){
       this.tableInventory = tableInventory;
       this.chairInventory = chairInventory;
       this.leafInventory = leafInventory;
       this.totalSales = 0;
       this.numSales = 0;
   }
   //---------------------------------------------------------------------------
   //      ASSESSORS
   //---------------------------------------------------------------------------

   public int getTableInventory(){
       return tableInventory;
    }

   public int getChairInventory(){
       return chairInventory;
   }

   public int getLeafInventory(){
       return leafInventory;
    }

   public int getTablesOnOrder(){
       return tableInventory;
    }

   public int getChairsOnOrder(){
       return chairInventory;
    }

   public int getLeavesOnOrder(){
       return leafInventory;
    }
    //---------------------------------------------------------------------------
    //      OTHER METHODS
    //---------------------------------------------------------------------------
   public double getTotalSales(){
       return totalSales;
    }

   public double getAvgOrderPrice(){
       return totalSales / numSales;
    }

   public String toString(){
        return "Table Inventory: " + tableInventory + "\n" + "Chair Inventory: " + chairInventory + "\n Leaf Inventory: " + leafInventory + "\n";
    }

    public double submitOrder(DinetteOrder order){
        int ordNum = order.getOrderNumber();
        int numChairs = order.getChairCount();
        int numLeaves = order.getLeafCount();
        **Option option = order.getOption();**

        return 0.02; // bogus return statement

    }
}


推荐答案

因为选项是位于 DinetteOrder 内的枚举,您需要参考您的 DinetteStore 中的 DinetteOrder.Option 类:

Because Option is an enum located within DinetteOrder, you'll need to refer to it as DinetteOrder.Option in your DinetteStore class:

DinetteOrder.Option option = order.getOption();

或者,您可以移动 Option 到自己的文件 Option.java

Alternatively, you could move the entire definition of Option to its own file Option.java:

public enum Option {
    cleanKit,
    seatCush,
    padFeet
};

这篇关于如何从访问器导入私有枚举类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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