⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bank.java

📁 模拟ATM取款机
💻 JAVA
字号:
package com.zfz.util;

import javax.swing.JOptionPane;

import com.zfz.atmInter.FileName;
import com.zfz.model.Account;
import com.zfz.model.DAO.ObjectInandOut;

public class Bank implements FileName {
	private Account[] user;
	private ObjectInandOut acc_out_in, sys_out_in;

	public Bank() {
		acc_out_in = new ObjectInandOut(FileName.accFile);
		sys_out_in = new ObjectInandOut(FileName.sysFile);
		while (true) {
			String sel = JOptionPane.showInputDialog("请输入操作:\n" 
					+ "1- 新建账户\n"
					+ "2- 操作已有账户\n" 
					+ "3- 退出系统");
			if (sel.equals("1")) {
				createAccount();
			} 
			else if (sel.equals("2")) {
				
				while (true) {
						String op_sel = JOptionPane
								.showInputDialog("---------请选择操作----------\n"
										+ "1 -- 解除用户锁定 \n" + 
										"2 -- 查看所有用户信息\n"+
										"3--退出");
						if(op_sel.equals("1")){
						   String s=JOptionPane.showInputDialog("请输入帐号");
						   String pass=JOptionPane.showInputDialog("请输入密码");
						   user = acc_out_in.myReadObj();
						   int ind=ifEnter(user,s,pass);
							if (ind != -1) {
						        ObjectInandOut getAllUser=new ObjectInandOut(accFile);
						    	user[ind].setFg(true);
						    	getAllUser.myWriteAllObj(user);
								JOptionPane.showMessageDialog(null, "解锁成功");
							}
							}
						if(op_sel.equals("2")){
							ObjectInandOut getAllUser=new ObjectInandOut(accFile);
							Account acc[]=getAllUser.myReadObj();
							for(int i=0;i<acc.length;i++){
								System.out.println(acc[i].getAllInfo());
							}
						}
						else{
							System.exit(0);
						}
						}

				}
			else if (sel.equals("3")) {
				System.exit(0);
			}

		}
	}

	// 建立账户---------------------------
	public void createAccount() {
		String name = JOptionPane.showInputDialog("输入用户名");
		String NO = sys_out_in.getAccountNo();
		sys_out_in.setAccountNo(Long.parseLong(NO) + 1 + "");
		double money = Double.parseDouble(JOptionPane
				.showInputDialog("输入用户开户金额"));
		String password = rePassword();
		boolean fg =true;
		Account acc = new Account(name, NO, money, password,fg);
		acc_out_in.myWriteObj(acc);
	}

	// 建立用户确认密码
	public String rePassword() {
		String password = "";
		while (true) {
			String password1 = JOptionPane.showInputDialog("输入用户开户密码");
			String password2 = JOptionPane.showInputDialog("输入用户确认密码");
			if (password1.equals(password2)) {
				password = password1;
				break;
			} else {
				JOptionPane.showMessageDialog(null, "密码验证不成功,请重新输入");
			}
		}
		return password;
	}

	public static int ifEnter(Account[] allAcc, String no, String password) {
		int index = -1;
		for (int i = 0; i < allAcc.length; i++) {
			if (allAcc[i].ifMyAccount(no, password)) {
				index = i;
				break;
			}
		}
		return index;
	}
	public static void main(String args[]) {
		new Bank();
		}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -