⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dispenser.java

📁 java编的售糖程序
💻 JAVA
字号:
//class Dispenser

package dsuj.ch01.candyMachine;

public class Dispenser
{
    private int numberOfItems;   //variable to store the number of
                                 //items in the dispenser
    private int cost;    //variable to store the cost of an item

       //Default constructor to set the cost and number of
       //items to the default values
       //Postconditions: numberOfItems  = 50;
       //                cost = 50;
    public Dispenser()
    {
         numberOfItems = 50;
         cost = 50;
    }

       //Constructor with parameters to set the cost and number
       //of items in the dispenser specified by the user
       //Postconditions: numberOfItems  = numberOfItems;
       //                cost = setCost;
    public Dispenser(int setNoOfItems, int setCost)
    {
       if(setNoOfItems >= 0)
            numberOfItems = setNoOfItems;
       else
            numberOfItems = 50;

       if(setCost >= 0)
         cost = setCost;
       else
         cost = 50;
    }

       //Method to show the number of items in the machine
       //Postconditions: The value of the data member
       //                numberOfItems  is returned
    public int getCount()
    {
       return numberOfItems;
    }

       //Method to show the cost of the item
       //Postconditions: The value of the data member
       //                cost is returned
    public int getProductCost()
    {
       return cost;
    }

       //Method to reduce the number of items by 1
       //Postconditions: numberOfItems = numberOfItems - 1;
    public void makeSale()
    {
       numberOfItems--;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -