Account.java
package ATM;//信1705-1 20173628 赵路仓
public class Account {
private int balance;//余额
private int amount;//取钱
private String ID;//卡号
private String passWord;//密码
private String name;//客户姓名
private String inputNum;//输入账户
private String inputWord;//输入密码
public double getBalance() {
return balance;
}
public void setBalance(int balance) {
this.balance = balance;
}
public double getMoney() {
return amount;
}
public void setMoney(int money) {
this.amount = money;
}
public String getCardsNum() {
return ID;
}
public void setCardsNum(String cardsNum) {
this.ID = cardsNum;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public String getInputNum() {
return ID;
}
public void setInputNum(String inputNum) {
this.ID = inputNum;
}
public String getInputWord() {
return ID;
}
public void setInputWord(String inputWord) {
this.inputWord = inputWord;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
AccountManager.java
package ATM;
import java.util.Scanner;
public class AccountManager {
Input input = new Input();
public void choose(Account atm) {
input.out();
System.out.println("请选择您要操作的项目(1-4):");
Scanner sc1 = new Scanner(System.in);
int num = sc1.nextInt();
switch (num) {
case 1:
getMoney(atm);
break;
case 2:
query(atm);
break;
case 3:
setPasswrod(atm);
break;
case 4:
exit();
break;
default:
error();
break;
}
}
public boolean getMoney(Account atm){
// input.out();
System.out.println("***************************************************************");
System.out.println("欢迎使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println("请输入取款金额;");
System.out.println("****************************************************************");
for(int i= 0;i<3;i++){
Scanner sc = new Scanner(System.in);
atm.setMoney(sc.nextInt());
if(atm.getMoney() > atm.getBalance()){
System.out.println("超过已有的钱数,请重新输入您要取的数目:");
}else{
System.out.println("取款成功,请收好您的钱");
return true;
}
}
return false;
}
public void query(Account atm){
System.out.println("客户账号:"+atm.getCardsNum());
System.out.println("客户名:"+atm.getName());
System.out.println("客户账户余额:"+atm.getBalance());
}
public void setPasswrod(Account atm){
System.out.println("请重新输入密码:");
Scanner sc1 = new Scanner(System.in);
String num = sc1.next();
atm.setPassWord(num);
System.out.println("您的密码为:"+"\n"+atm.getPassWord());
}
public void exit(){
System.out.println("感谢您使用本系统,欢迎下次再来,再见!");
System.exit(0);
}
public void error(){
//shurude shuju
System.out.println("输入的数据有误");
}
}
input.java
package ATM;
import java.util.Scanner;
public class Input {
public void out(){
System.out.println("***************************************************************");
System.out.println("欢迎使用中国工商银行自助柜员系统");
System.out.println(" ");
System.out.println("*********************************************");
System.out.println("1.取款.\n2.>查询信息.\n3.密码设置.\n4.退出系统.");
}
public boolean input(String card, String password){
for (int i = 0; i < 3; i++) {
System.out.println("***************************************************************");
System.out.println("欢迎使用中国工商银行自动柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入您的账户:");
System.out.println("***************************************************************");
Scanner sc1 = new Scanner(System.in); // 输入卡号
String inputCard = sc1.next();
System.out.println("***************************************************************");
System.out.println("欢迎使用中国工商银行自动柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入您的密码:");
System.out.println("***************************************************************");
Scanner sc2 = new Scanner(System.in); //输入密码
String inputWord = sc2.next();
if (card == inputCard && password == inputWord) {
return true;
}else {
if (i == 2) {
System.out.println("对不起,输入错误已达三次,您的卡已经被没收");
}else {
System.out.println("您的卡号或密码输入有误.");
}
}
}
return false;
}
}
Testdocuments.java
package ATM;
public class Testdocumets {
public static void main(String[] args) {
Account atm = new Account();
atm.setBalance(2000);
atm.setCardsNum("20173628");
atm.setPassWord("20173628");
atm.setName("赵路仓");
Input input = new Input();
input.out();
boolean result = input.input(atm.getCardsNum(), atm.getPassWord());
AccountManager operation = new AccountManager();
if (result) {
operation.choose(atm);
}
}
}