📄 cashregister.java
字号:
//class cashRegister
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -