案例題-------銀行存取款系統(BSWS)軟體系統模擬

zzz555683發表於2020-12-10

銀行存取款系統(BSWS)軟體是一款通用效能極強的銀行存取款管理系統,軟體功能囊括了銀行從使用者開戶到最終銷戶等業務的全過程。軟體適用於各級各類的銀行。軟體覆蓋銀行業的現金辦理與金融轉賬業務,軟體的各個模組操作介面簡單、實用,軟體幫助系統讓使用者可以在最短的時間內掌握軟體的使用方法,幫助使用者生意更上一層樓。軟體系統採用銀行軟體業務能用的控制檯操作介面,操作簡單易學。

系統基本模組包括:

​ 功能點:

​ 1.開戶

​ 2.存款

​ 3.取款

​ 4.修改密碼

​ 5.查詢

​ 6.轉賬

​ 7.銷戶

功能點介紹

​ 1.開戶

​ 開戶時需要儲戶輸入個人資訊,包括姓名,開戶金額,完成後儲蓄資訊被儲存到一個儲戶基本資訊檔案中,並反饋給儲戶開戶後的賬號,初始密碼,開戶金額,開戶日期。同時生成一個操作記錄包括賬號,操作型別,操作金額,本次操作的具體時間,舊密碼,新密碼
在這裡插入圖片描述

​ 2.存款

​ 存款時儲戶提供事先獲得的賬號及儲存的金額(現金),將金額加到賬戶原有金額中,然後返回本次操作的資訊包括儲存的金額,賬號中現有金額,操作時間。同時生成一個一個操作記錄包括賬號,操作型別,操作金額,本次操作的具體時間,舊密碼,新密碼
在這裡插入圖片描述

​ 3.取款

​ 取款時儲戶提供事先獲取的賬號及要提取的金額(金額),將賬號中原有的金額減去要提取的金額,將現金交給儲戶,然後返回本次操作的資訊包括提取的金額,賬號中原有的金額,操作的時間。同時生成一個操作記錄包括賬號,操作型別,操作金額,本次操作的具體時間,舊密碼,新密碼

在這裡插入圖片描述

​ 4.查詢

​ 查詢時儲戶提供賬號,密碼。返回查詢資訊包括賬號,操作型別,操作金額,操作具體時間,舊密碼,新密碼。

在這裡插入圖片描述

​ 5.修改密碼

​ 修改密碼時儲戶提供賬號及密碼,根據提示輸入新密碼兩次(兩次輸入必須相同),完成後密碼修改成功。同時生成一個操作記錄包括賬號,操作型別,操作金額,本次操作的具體時間,舊密碼,新密碼。
在這裡插入圖片描述
6.轉賬

​ 轉賬時儲戶提供事先獲得轉出賬號,轉出賬號密碼,轉入賬號,轉賬金額,將轉出賬號中的金額減去轉賬金額,轉入賬號中的金額加上轉賬金額,然後返回本次操作的資訊包括轉賬的金額,轉出賬號現有的金額,本次操作的時間。同時生成一個操作記錄包括賬號,操作型別,操作金額,本次操作的具體時間,舊密碼,新密碼
在這裡插入圖片描述

​ 7.銷戶

​ 銷戶時儲戶提供賬號及密碼,將賬號中的金額全部取出,然後將本賬戶的資訊從檔案中刪除(由於沒有學習檔案操作,改為集合刪除賬戶資訊),返回銷戶成功 在這裡插入圖片描述
1.銀行賬戶類


package com.zhiyou100.bank.pojo;

import java.util.ArrayList;

public class Account {

	private int password;
	private String name;
	private String personId;
	private double balance;
	private int id;
	private String time;
	private ArrayList<rizhi> rizhis = new ArrayList<>();

	public ArrayList<rizhi> getRizhis() {
		return rizhis;
	}

	public void setRizhis(ArrayList<rizhi> rizhis) {
		this.rizhis = rizhis;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public Account() {
		super();
	}

	public Account(int password, String name, String personId, double balance, int id, String time) {
		super();
		this.password = password;
		this.name = name;
		this.personId = personId;
		this.balance = balance;
		this.id = id;
		this.time = time;
	}

	@Override
	public String toString() {
		return "戶主:" + name + ", 密碼:" + password + ", 餘額:" + balance + ", 賬號:" + id;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Account(int password, String name, String personId, double balance, int id) {
		super();
		this.password = password;
		this.name = name;
		this.personId = personId;
		this.balance = balance;
		this.id = id;
	}

	public Account(int id, String name, int balance, int password) {
		super();
		this.id = id;
		this.name = name;
		this.balance = balance;
		this.password = password;
	}

	public Account(int password, String name, String personId, double balance) {
		super();
		this.password = password;
		this.name = name;
		this.personId = personId;
		this.balance = balance;
	}

	public int getPassword() {
		return password;
	}

	public void setPassword(int password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPersonId() {
		return personId;
	}

	public void setPersonId(String personId) {
		this.personId = personId;
	}

	public double getBalance() {
		return balance;
	}

	public void setBalance(double balance) {
		this.balance = balance;
	}	
}

日誌類

package com.zhiyou100.bank.pojo;

public class rizhi {
	
	private String type;
	private int balance;
	private int oldPassword;
	private int newPassword;
	private String time;
	public rizhi() {
		super();
	}
	public rizhi(String type, int balance, int oldPassword, int newPassword, String time) {
		super();
		this.type = type;
		this.balance = balance;
		this.oldPassword = oldPassword;
		this.newPassword = newPassword;
		this.time = time;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public int getBalance() {
		return balance;
	}
	public void setBalance(int balance) {
		this.balance = balance;
	}
	public int getOldPassword() {
		return oldPassword;
	}
	public void setOldPassword(int oldPassword) {
		this.oldPassword = oldPassword;
	}
	public int getNewPassword() {
		return newPassword;
	}
	public void setNewPassword(int newPassword) {
		this.newPassword = newPassword;
	}
	public String getTime() {
		return time;
	}
	public void setTime(String time) {
		this.time = time;
	}
	@Override
	public String toString() {
		return "操作型別:" + type + "  流動金額:" + balance + " 舊密碼:" + oldPassword + " 新密碼:"
				+ newPassword + " 時間:" + time ;
	}
}

3.工具類

package com.zhiyou100.bank.tools;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import com.zhiyou100.bank.pojo.Account;
import com.zhiyou100.bank.pojo.rizhi;

public class Tools {
	static int id = 10000;
	private static ArrayList<Account> list;

	public static int getId() {
		return id;
	}

	public static void setId(int id) {
		Tools.id = id;
	}

	public static ArrayList<Account> getList() {
		return list;
	}

	public static void setList(ArrayList<Account> list) {
		Tools.list = list;
	}

	// 1.開戶
	public void kaihu(String name, int password, int repw, int balance) {

		if (password == repw) {
			System.out.println("恭喜你開戶成功");
			id++;
			System.out.println("你的賬號為:" + id);
			System.out.println("你的密碼為:" + password + ",請牢記密碼");
			list.add(new Account(id, name, balance, password));
			String time = time();
			list.get(list.size() - 1).getRizhis().add(new rizhi("開戶", balance, password, password, time));

		} else {
			System.out.println("兩次輸入的密碼不一致,開戶失敗!");
		}
	}

	// 2.存款
	public void deposit(int id, int money,int password) {
		boolean kaiguan = true;
		for (int i = 0; i < list.size(); i++) {

			if (list.get(i).getId() == id) {
				kaiguan = false;
				if (money > 0) {
					list.get(i).setBalance(money + list.get(i).getBalance());
					System.out.println("存款成功!");
					System.out.println("您的存款金額為:" + money);
					System.out.println("您的餘額是:" + list.get(i).getBalance());
					String time = time();
ArrayList<rizhi> rizhis = list.get(i).getRizhis();
					
					list.get(i).getRizhis().add(new rizhi("存款", money, rizhis.get(rizhis.size()-1).getOldPassword(), password, time));
				}
			}
		}
		if (kaiguan) {

			System.out.println("賬號不匹配!請慎重輸入!");

		}
	}

	// 3.取款
	public void withdraw(int id, int money, int password) {
		boolean kaiguan = true;
		boolean kaiguan2 = false;
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getId() == id) {
				kaiguan = false;
				if (list.get(i).getPassword() == password) {
					kaiguan2 = false;
					if (list.get(i).getBalance() >= money && money > 0) {
						list.get(i).setBalance(list.get(i).getBalance() - money);
						System.out.println("恭喜你取款成功!");
						System.out.println("您的餘額是:" + list.get(i).getBalance());
						String time = time();
						ArrayList<rizhi> rizhis = list.get(i).getRizhis();
						
						list.get(i).getRizhis().add(new rizhi("取款", money, rizhis.get(rizhis.size()-1).getOldPassword(), password, time));
						return;
					}
				}
			}
		}
		if (kaiguan) {
			System.out.println("該賬戶不存在!");
		}
		if (kaiguan2) {
			System.out.println("餘額不足!");
		} else {
			System.out.println("密碼不正確!");
		}

	}

	// 4.查詢
	public void check(int id, int password) {
		boolean kaiguan = true;
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getId() == id && list.get(i).getPassword() == password) {
				kaiguan = false;
				System.out.println("查詢成功");
				System.out.println("您的賬戶資訊是:");
				System.out.println(list.get(i).toString());
				for (int j = list.get(i).getRizhis().size() - 1; j >= 0; j--) {
					System.out.println(list.get(i).getRizhis().get(j).toString());
				}

				return;
			}
		}
		if (kaiguan) {

			System.out.println("沒有該賬戶資訊,請確定你輸入的賬號和密碼正確");

		}

	}

	// 5.修改密碼
	public void xiugai(int id3, int password4, int password5, int password6) {
		boolean kaiguan = true;
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getId() == id3 && list.get(i).getPassword() == password4) {
				kaiguan = false;
				if (password5 == password6) {
					list.get(i).setPassword(password5);
					System.out.println("恭喜你修改成功!");
					System.out.println("您的新密碼為:" + password5 + "(請牢記新密碼!)");
					String time = time();
					ArrayList<rizhi> rizhis = list.get(i).getRizhis();
					
					list.get(i).getRizhis().add(new rizhi("修改密碼", 0, rizhis.get(rizhis.size()-1).getNewPassword(), password5, time));
					return;
				}

			}

		}
		if (kaiguan) {
			System.out.println("賬號或者密碼不正確");
		} else {
			System.out.println("兩次輸入的密碼不一致!");
		}
	}

	// 6.轉賬
	public void zhuanzhang(int id, int password, int id2, int money) {
		boolean kaiguan = true;

		for (int i = 0; i < list.size(); i++) {

			if (list.get(i).getId() == id && list.get(i).getPassword() == password) {
				kaiguan = false;
				for (int j = 0; j < list.size(); j++) {
					if (list.get(j).getId() == id2) {
						list.get(i).setBalance(list.get(i).getBalance() - money);
						System.out.println(list.get(i).toString());
						list.get(j).setBalance(list.get(j).getBalance() + money);
						System.out.println(list.get(j).toString());
						System.out.println("轉賬成功");
						String time = time();
						ArrayList<rizhi> rizhis = list.get(i).getRizhis();
						
						list.get(i).getRizhis().add(new rizhi("轉賬", money, rizhis.get(rizhis.size()-1).getOldPassword(), password, time));
						return;
					}

				}

			}
		}
		if (kaiguan) {
			System.out.println("賬號密碼不正確!");
		} else {
			System.out.println("被轉賬賬戶不存在!");
		}
	}
	// 銷戶
	public void xiaohu(int id, int password) {
		boolean kaiguan = true;
		for (int i = 0; i < list.size(); i++) {
			kaiguan = false;
			if (list.get(i).getId() == id && list.get(i).getPassword() == password) {
				if (list.get(i).getBalance() > 0) {
					System.out.println("您的賬戶還有餘額,請全部取出後再銷戶!");
					System.out.println("您的餘額為:" + list.get(i).getBalance());
					return;
				} else {
					list.remove(i);
					System.out.println("銷戶完成");
					System.out.println("歡迎您下次光臨");
					return;
				}
			}
		}
		if (kaiguan) {
			System.out.println("賬號或者密碼不正確");

		}
	}
	public String time() {
		Date d = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String sj = sdf.format(d);
		System.out.println(sj);
		return sj;
	}

}

4.主介面

package com.zhiyou100.bank.main;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;

import com.zhiyou100.bank.pojo.Account;
import com.zhiyou100.bank.pojo.rizhi;
import com.zhiyou100.bank.tools.Tools;

public class Controller {
	public static void main(String[] args) {
		ArrayList<Account> list = new ArrayList<>();
		Tools.setList(list);
		Tools tools = new Tools();
		while (true) {
			System.out.println("************************");
			System.out.println("                    銀行管理系統                                                     ");
			System.out.println("************************");
			System.out.println("         1.開戶");
			System.out.println("         2.存款");
			System.out.println("         3.取款");
			System.out.println("         4.查詢");
			System.out.println("         5.修改密碼");
			System.out.println("         6.轉賬");
			System.out.println("         7.銷戶");
			System.out.println("         8.退出系統");
			System.out.println("------------------------");
			System.out.println("請選擇你要辦理的業務:");
			Scanner scanner = new Scanner(System.in);
			int i = scanner.nextInt();

			switch (i) {
			case 1:
				System.out.println("歡迎您來辦理開戶業務,請根據系統提示輸入!");
				System.out.println("請輸入姓名:");
				String name = scanner.next();
				System.out.println("請輸入密碼:");
				int password = scanner.nextInt();
				System.out.println("請再次輸入密碼:");
				int repw = scanner.nextInt();
				System.out.println("請輸入初始金額:");
				int balance = scanner.nextInt();
				System.out.println("請稍等,正在開戶中.....");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("------------------------");
				tools.kaihu(name, password, repw, balance);
				break;
			case 2:
				System.out.println("歡迎您來辦理存款業務,請根據系統提示輸入!");
				System.out.println("請輸入賬號:");
				int id = scanner.nextInt();
				System.out.println("請輸入密碼:");
				int password123 = scanner.nextInt();
				
				System.out.println("請輸入存款金額:");
				int balance1 = scanner.nextInt();
				System.out.println("請稍等,正在存款中.....");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("------------------------");
				tools.deposit(id, balance1,password123);
				break;
			case 3:
				System.out.println("歡迎您來辦理取款業務,請根據系統提示輸入!");
				System.out.println("請輸入賬號:");
				int id1 = scanner.nextInt();
				System.out.println("請輸入密碼:");
				int password2 = scanner.nextInt();
				System.out.println("請輸入取款金額:");
				int money = scanner.nextInt();
				System.out.println("請稍等,正在取款中.....");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("------------------------");
				tools.withdraw(id1, money, password2);

				break;
			case 4:
				System.out.println("歡迎您來辦理查詢業務,請根據系統提示輸入!");
				System.out.println("請輸入賬號:");
				int id2 = scanner.nextInt();
				System.out.println("請輸入密碼:");
				int password3 = scanner.nextInt();
				System.out.println("請稍等,正在查詢中.....");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("------------------------");
				tools.check(id2, password3);

				break;
			case 5:
				System.out.println("歡迎您來辦理修改密碼業務,請根據系統提示輸入!");
				System.out.println("請輸入賬號:");
				int id3 = scanner.nextInt();
				System.out.println("請輸入密碼:");
				int password4 = scanner.nextInt();
				System.out.println("請輸入新密碼");
				int password5 = scanner.nextInt();
				System.out.println("請再次輸入新密碼");
				int password6 = scanner.nextInt();
				System.out.println("請稍等,正在修改中.....");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("------------------------");
				tools.xiugai(id3, password4, password5, password6);
				tools.time();
				break;
			case 6:
				System.out.println("歡迎您來辦理轉賬業務,請根據系統提示輸入!");
				System.out.println("請輸入賬號:");
				int id4 = scanner.nextInt();
				System.out.println("請輸入密碼:");
				int password7 = scanner.nextInt();
				System.out.println("請輸入要轉入的賬號:");
				int id5 = scanner.nextInt();
				System.out.println("請輸入轉賬金額:");
				int money1 = scanner.nextInt();
				System.out.println("請稍等,正在轉賬中.....");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("------------------------");
				tools.zhuanzhang(id4, password7, id5, money1);
				tools.time();
				break;
			case 7:
				System.out.println("歡迎您來辦理銷戶業務,請根據系統提示輸入!");
				System.out.println("請輸入賬號:");
				int id6 = scanner.nextInt();
				System.out.println("請輸入密碼:");
				int password8 = scanner.nextInt();
				System.out.println("請稍等,正在銷戶中.....");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("------------------------");
				tools.xiaohu(id6, password8);
				tools.time();
				break;
			case 8:
				System.out.println("歡迎下次光臨!!");
				System.exit(1);
				tools.time();
				break;
			default:
				break;
			}
			

		}

	}

}

相關文章