📄 account.java
字号:
/** A simple bank account class that is an implementation of the interface AccountADT. */
public class Account implements AccountADT
{
/** The name of the owner. */
private String owner;
/** The current balance in the account. */
private float balance;
/** The current line of credit for the account. */
private float lineOfCredit;
/** The name of the owner.
Analysis: Time = O(1) */
public String owner()
{
return owner;
}
/** The current balance in the account.
Analysis: Time = O(1) */
public float balance()
{
return balance;
}
/** The current line of credit for the account.
Analysis: Time = O(1) */
public float lineOfCredit()
{
return lineOfCredit;
}
/** Create bank account.
Analysis: Time = O(1)
PRECONDITION:
amount >= 0
openingLoc >= 0
POSTCONDITION:
owner == name
balance == openingAmount
lineOfCredit == openingLoc */
public Account(String name, float openingAmount, float openingLOC)
{
owner = name;
balance = openingAmount;
lineOfCredit = openingLOC;
}
/** Deposit an amount in the account.
Analysis: Time = O(1)
PRECONDITION:
amount >= 0
POSTCONDITION:
balance() == entry(balance()) + amount
owner() == entry(owner())
lineOfCredit() == entry(lineOfCredit()) */
public void deposit(float amount)
{
balance += amount;
}
/** Withdraw an amount from the account.
Analysis: Time = O(1)
PRECONDITION:
amount >= 0
amount <= balance() + lineOfCredit()
POSTCONDITION:
balance() == entry(balance()) - amount
owner() == entry(owner())
lineOfCredit() == entry(lineOfCredit()) */
public void withdraw(float amount)
{
balance -= amount;
}
/** Change approved line of credit for the account.
Analysis: Time = O(1)
PRECONDITION:
amount >= 0
balance() >= -amount
POSTCONDITION:
balance() == entry(balance())
owner() == entry(owner())
lineOfCredit() == amount */
public void changeLOC(float amount)
{
lineOfCredit = amount;
}
/** INVARIANT:
lineOfCredit() >= 0
balance() >= -lineOfCredit() */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -