برمجة شيئية | همّة: post #256 — TG.ME

//Lab 10_fill_3 
public class SavingsAccount extends BankAccount{
private double profit;
private double profitPercent;
public SavingsAccount(){
super();
profit=0;
profitPercent=.06;
}
public SavingsAccount(int accountNum, double initialBalance,double profit){
super(accountNum,initialBalance);
this.profit=profit;
profitPercent=.06;
}
public SavingsAccount(int accountNum, String aCurrenc,double profit){
super(accountNum,aCurrenc);
this.profit=profit;
profitPercent=.06;
}
public SavingsAccount(int accountNum,double initialBalance,String aCurrency,double profit){
super(accountNum,initialBalance,aCurrency);
this.profit=profit;
profitPercent=.06;
}
public double getProfitPercent() {
return profitPercent;
}
public void setProfitPercent(double profitPercent) {
this.profitPercent = profitPercent;
}
public boolean deposit(double amount){
if (amount<1000)
return false;
else
return super.deposit(amount);
}
public boolean withdraw(double amount){
if(super.withdraw(amount)){
profit=0;
return true;
}
else{
return false;
}
}
public void setProfit(double p){
this.profit=profit;
}
public double getProfit(){
return profit;
}
public String toString(){
profit=balance*profitPercent;
double totalBalance=balance+profit;
String text=String.format("Saving Account number [%d] includes %.2f profit %.2f %s %.2f", accountNumber,balance,profit,currency,totalBalance);
return text;
}
}
July 1, 2024 2.4K 9