cashregister.java

来自「java编的售糖程序」· Java 代码 · 共 46 行

JAVA
46
字号
//class cashRegister

package dsuj.ch01.candyMachine;

public class CashRegister

{
    private int cashOnHand;   //variable to store the cash
                              //in the register

        //Constructor with parameters
        //To set the cash in the register to a specific amount
        //Postcondition: cashOnHand = cashIn;
    public CashRegister(int cashIn)
    {
        if(cashIn >= 0)
         cashOnHand = cashIn;
        else
             cashOnHand = 500;
    }

        //Default constructor with parameters
        //To set the cash in the register 500 cents
        //Postcondition: cashOnHand = 500;
    public CashRegister()
    {
         cashOnHand = 500;
    }

        //Method to show the current amount in the cash register
      //Postcondition: The value of the instance variable
        //               cashOnHand is returned
    public int currentBalance()
    {
      return cashOnHand;
    }

        //Method to receive the amount deposited by
        //the customer and update the amount in the register.
        //Postcondition: cashOnHand = cashOnHand + amountIn
    public void acceptAmount(int amountIn)
    {
        cashOnHand = cashOnHand + amountIn;
    }
}

⌨️ 快捷键说明

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