📄 savingsaccount.java
字号:
//********************************************************
// SavingsAccount,java Author:ZhaoHaiyan
//
// deposit and withdraw money from savingsAccount
// close and open the savingsAccount
//********************************************************
public class SavingsAccount extends BankAccount
{
boolean open;
final int fee=5; //withdrawal fee
public SavingsAccount(int initialDeposit) //constructor
{
super();
setBalance(initialDeposit);
open=true;
}
public boolean withdraw(int amount)
{
if(fee+amount<=getBalance()&&open==true) //withdraw is successful
{
System.out.println("enter the amount:");
setBalance(getBalance()-amount-fee);
return true;
}
else if(fee+amount>getBalance()&&open==true) //withdraw is failed
{
System.out.println(" the withdrawal amount of fee is"+
" greater than the current balance");
return false;
}
else if(fee+amount<=getBalance() && open==false)//withdraw is failed
{
System.out.println("account is not open");
return false;
}
else //withdraw is failed
{
System.out.println( "account is not open,and balance is too low");
return false;
}
}
public boolean deposit(int amount)
{
if(open==true) //deposit is successful
{
System.out.println("enter the amount :");
setBalance(getBalance()+amount);
return true;
}
else //deposit is failed
{
System.out.println(" account is not open");
return false;
}
}
public boolean CloseAccount() //close the account
{
if(open==false)
{
System.out.println("the operation could not be done.");
return false;
}
else
{
open=false;
setBalance(0);
return true;
}
}
public boolean IsOpen() //judge the account if is open
{
if(open==true)
return true;
else
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -