银行管理系统之Java语言实现

BankSysterm1实验报告

系统需求:

这个银行管理系统主要实现的用户需求有:

1:实现对存取现金后对账户余额的更新功能。

2:在每年的1月1日进行利息的结算。

3:显示用户账户的信息。

4:获取账户的账号,余额,存款的年利率。

5:获得指定日期为止的存款金额按日累积值。

系统的设计:

本次代码主要是通过一个SavingsAccount类来实现上述系统所需求的功能

private class SavingsAccount { //储蓄账户类

扫描二维码关注公众号,回复: 4977364 查看本文章

       private int id;                      //账号

private    double balance;           //余额

private    double rate;          //存款的年利率

       private int lastDate;             //上次变更余额的时期

       private double accumulation;     //余额按日累加之和

       //记录一笔帐,date为日期,amount为金额,desc为说明

       private void record(int date, double amount){}

       //获得到指定日期为止的存款金额按日累积值

       private double accumulate(int date){}

       //构造函数

       public SavingsAccount(int date, int id, double rate){}

       public int getId() { return id; }

       public double getBalance() { return balance; }

       public double getRate() { return rate; }

       //存入现金

       public void deposit(int date, double amount){}

       //取出现金

public void withdraw(int date, double amount){}

       //结算利息,每年1月1日调用一次该函数

public     void settle(int date){}

       //显示账户信息

       public void show(){}

import Account.* ;

public class BankSystem {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SavingsAccount sa0=new SavingsAccount(1, 21325302, 0.015);
		SavingsAccount sa1=new  SavingsAccount(1, 58320212, 0.015);

		//几笔账目
		sa0.deposit(5, 5000);
		sa1.deposit(25, 10000);
		sa0.deposit(45, 5500);
		sa1.withdraw(60, 4000);

		//开户后第90天到了银行的计息日,结算所有账户的年息
		sa0.settle(90);
		sa1.settle(90);

		//输出各个账户信息
		sa0.show();
		sa1.show();	
	}

}
package Account;

public class SavingsAccount {
		private int id;				//账号
		private double balance;		//余额
		private double rate;		//存款的年利率
		private int lastDate;		//上次变更余额的时期
		private double accumulation;	//余额按日累加之和

		//记录一笔帐,date为日期,amount为金额,desc为说明
	private void record(int date, double amount){
		accumulation = accumulate(date);
		lastDate = date;
		amount = (amount * 100 + 0.5) / 100;	//保留小数点后两位
		balance += amount;
		System.out.println(date+"\t#"+id+ "\t"+ amount +"\t" + balance );
		
	}
		//获得到指定日期为止的存款金额按日累积值
	private	double accumulate(int date) {
			return accumulation + balance * (date - lastDate);
		}
		//构造函数
		public SavingsAccount(int date, int id, double rate){
			this.id=id;
		    this.balance=0;
		    this.rate=rate;
		    this.lastDate=date;
		    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);
		}
		//结算利息,每年1月1日调用一次该函数
		public void settle(int date){
			double interest = accumulate(date) * rate / 365;	//计算年息
			if (interest != 0)
				record(date, interest);
			accumulation = 0;
		}
		//显示账户信息
		public void show(){
			System.out.println( "#" + id+ "\tBalance: "+ balance);
		}
	};

猜你喜欢

转载自blog.csdn.net/qq_41989372/article/details/85106135