1、Account anotherAcc=(Account)obj;if(this.id=anotherAcc.id)rt=true;return rt;public int hashCode() return password.hashCode()+name.hashCode()+personId.hashCode()+email.hashCode();public String toString() return id+;+password+name+personId+email+balance;/* 无参构造体 */public Account() /* 有参构造体,用于初始化对象的必要属性
2、 */public Account(long id, String password, String name, String personId,String email, double balance)this.setId(id);this.setPassword(password);this.setName(name);this.setPersonId(personId);this.setEmail(email);this.setBalance(balance);/* 存款方法 */public void deposit(double money) balance+=money;/* 取款
3、方法,抽象类,行为不确定,有储蓄账户和信用账户之分 * throws BalanceNotEnoughException */public abstract void withdraw(double money) throws BalanceNotEnoughException;/* 属性的封装 */public void setId(long id) this.id = id;public long getId() return id;public void setPassword(String password) this.password = password;public String
4、 getPassword() return password;public void setName(String name) this.name = name;public String getName() return name;public void setPersonId(String personId) this.personId = personId;public String getPersonId() return personId;public void setEmail(String email) this.email = email;public String getEm
5、ail() return email;public void setBalance(double balance) this.balance = balance;public double getBalance() return balance;2) ATM.java类import java.io.*;public class ATM private Bank bank;public ATM() /* 初始化Bank类,此时调用Bank的构造函数,其中默认的两个测试用户的信息被添加到Account类中 */bank = new Bank();public static void main(St
6、ring args) ATM atm = new ATM();atm.mainMenu();private void mainMenu() boolean outflag = true;do System.out.println( ATM服务系统);* 1. 登 录 2. 开 户 0. 退 出System.out.print(请选择操作:Scanner scanner = new Scanner(System.in);String firstChoice;do firstChoice = scanner.next();if (firstChoice.matches(0-2$) break; e
7、lseSystem.out.println(选择输入错误! while (true);boolean rt = true;out: do switch (Integer.parseInt(firstChoice) case 1:/* 进入登录界面或登录成功界面 */secondMenu();break out;case 2:/* 开户 ,捕捉createAccount方法抛出的所有异常 */try bank.createAccount(); catch (RegisterException e) System.out.println(e.toString();rt = false;case 0
8、:outflag = false;default: while (rt); while (outflag);System.out.println(谢谢您的使用!/* 登录成功后的二级菜单 */private void secondMenu() Scanner scanner = new Scanner(System.in);Account account = null;out: dotry /* 输入卡号,输入exit可以直接退出系统 */System.out.print(输入卡号:String cardNo0;long cardNo;out1:cardNo0 = scanner.next()
9、;if (cardNo0.equals(exit) | cardNo0.equals(EXITbreak out; else if (cardNo0.matches(0-9_+$cardNo = Long.parseLong(cardNo0);break out1; elseSystem.out.println(请输入数字类型的ID! while (true);/* 输入密码,输入exit可以直接退出系统 */密码:String password = scanner.next();if (password.equals() | password.equals(account = bank.login(cardNo, password);break out; catch (LoginException e) System.out.println(e.toString();while (true);if (account != null) System.out.println( ATM操作界面 1. 存款操作 2. 取款操作 3. 查询余额 4. 设置透支额度 5. 统计银行总余额 6. 查询本人信息 0. 退 出scanner = new Scanner(System.in);String sc;do sc
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1