Java 运行效果
c++运行效果
public class SavingsAccount {
private int Id;
private double Balance;
private double Rate;
private int LastDate;
private double Accumulation;
private void Record(int date, double amount){
Accumulation = Accumulation(date);
LastDate = date;
Balance = Balance + amount;
Balance = (double)(Math.round(Balance * 100)/100.0);
System.out.println( date+ "\t#" + Id + "\t" + amount +"\t" +Balance);
}
private double Accumulation(int date){
return Accumulation + Balance * (date-LastDate);
}
SavingsAccount(int date,int id,double rate){
Id=id;
LastDate=date;
Balance=0;
Rate=rate;
Accumulation=0;
System.out.println(date + "\t#" + id +" is created!");
}
public int GetId(){return Id;}
public double GetBalance(){ return Balance;}
public double GetRate(){ return Rate;}
public void Deposit(int date , double amount){
Record(date, amount);
}
public void WithDraw(int date, double amount){
if(amount > GetBalance()) {
System.out.println("Error: not enough money!");
}
else{
Record(date, -amount);
}
}
public void Settle(int date){
double Interest = Accumulation(date)*Rate/365;
if(Interest != 0 ){
Record(date, Interest);
}
Accumulation = 0;
}
public void Show(){
System.out.println("#" + Id + "\tBalance:" + Balance);
}
public static void main(String[] args) {
SavingsAccount SA1;
SavingsAccount SA2;
SA1 = new SavingsAccount(1, 21325302, 0.015);
SA2 = new SavingsAccount(1, 58320212, 0.015);
SA1.Deposit(5, 5000);
SA2.Deposit(25, 10000);
SA1.Deposit(45,5500);
SA2.WithDraw(60, 4000);
SA1.Settle(90);
SA2.Settle(90);
SA1.Show();
SA2.Show();
}
}