Java重构银行管理系统1.1

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();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值