dispenser.java
来自「java编的售糖程序」· Java 代码 · 共 61 行
JAVA
61 行
//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 + =
减小字号Ctrl + -
显示快捷键?