银行管理系统JAVA

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1)Account.java类

package com.etp;

import java.util.*;

public abstract class Account {

protected long id;

protected String password;

protected String name;

protected String personId;

protected String email;

protected double balance;

@Override

public boolean equals(Object obj) {

boolean rt=false;

if(this==obj)

rt=true;

if(obj instanceof Account)

{

Account anotherAcc=(Account)obj;

if(this.id==anotherAcc.id)

rt=true;

}

return rt;

}

@Override

public int hashCode() {

return

password.hashCode()+name.hashCode()+personId.hashCode()+email.hashCode();

}

@Override

public String toString() {

return id+";"+password+";"+name+";"+personId+";"+email+";"+balance;

}

/** 无参构造体*/

public Account() {

}

/** 有参构造体,用于初始化对象的必要属性*/

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;

}

/** 取款方法,抽象类,行为不确定,有储蓄账户和信用账户之分

* @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 getPassword() {

return password;

}

public void setName(String 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 getEmail() {

return email;

}

public void setBalance(double balance) {

this.balance = balance;

}

public double getBalance() {

return balance;

}

}

2)ATM.java类

package com.etp;

import java.util.*;

import java.io.*;

public class ATM {

private Bank bank;

public ATM() {

/* 初始化Bank类,此时调用Bank的构造函数,其中默认的两个测试用户的信息被添加到Account类中*/

bank = new Bank();

public static void main(String[] args) {

ATM atm = new ATM();

atm.mainMenu();

}

private void mainMenu() {

boolean outflag = true;

do {

System.out.println(" ATM服务系统");

System.out.println("****************");

System.out.println(" 1. 登录");

System.out.println(" 2. 开户");

System.out.println(" 0. 退出");

System.out.println("****************");

System.out.print("请选择操作:");

Scanner scanner = new Scanner(System.in);

String firstChoice;

do {

firstChoice = scanner.next();

if (firstChoice.matches("^[0-2]$")) {

break;

} else

System.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;

相关文档
最新文档