ATM模拟系统项目题目要求开发一个控制台ATM模拟系统实现以下功能①主界面需要用户登录与用户开户两个功能。②开户功能输入姓名、性别男/女设置密码并确认设置取现限额系统自动生成8位随机卡号账户存入系统③ 登录功能若系统中没有开户则不允许登录输入卡号和密码验证登录成功后进入业务界面④业务功能查询账户显示卡号、姓名、性别、余额、限额存款输入金额更新余额取款检查余额和限额转账1验证对方卡号2隐藏此账户户主的姓氏请求确认3金额不能超限额/余额修改密码加确认退出返回主界面注销账户余额必须为0时才可注销且要确认是否注销··设计思路账户有卡号、姓名、性别、余额、限额所以要用面向对象编程创建实体类来封装信息又因为对象数目不固定所以要用集合来存储对象的地址。··代码实现①实体类package com.itheiama.ATMsystem;//系统的实体类public class ATMSystem {private String name;//账户名private String card;//卡号private int password;//密码private String gender;//性别private double balance;//余额private double quota;//限额public ATMSystem() {}public ATMSystem(String name, String card, int password, String gender, double balance, double quota) {this.name name;this.card card;this.password password;this.gender gender;this.balance balance;this.quota quota;}public String getName() {return name;}public void setName(String name) {this.name name;}public String getCard() {return card;}public void setCard(String card) {this.card card;}public int getPassword() {return password;}public void setPassword(int password) {this.password password;}public String getGender() {return gender;}public void setGender(String gender) {this.gender gender;}public double getBalance() {return balance;}public void setBalance(double balance) {this.balance balance;}public double getQuota() {return quota;}public void setQuota(double quota) {this.quota quota;}}②ATM系统方法类package com.itheiama.ATMsystem;import java.util.ArrayList;import java.util.Random;import java.util.Scanner;//ATM系统方法类public class ATMSystemOperator {private ArrayList list new ArrayList();//定义一个实体类的集合private int choice1;private int choice2;private String sure;Scanner sc new Scanner(System.in);Random r new Random();//构造器用于创建系统界面public ATMSystemOperator() {while (true) {System.out.println(“欢迎来到ATM系统”);System.out.println(“1,用户登录”);System.out.println(“2用户开户”);System.out.println(“请选择你的操作”);choice1 sc.nextInt();switch (choice1) {case 1:if (list.size() 0) {System.out.println(“当前系统无账户无法登录”);continue;}int index login();String gender list.get(index).getGender().equals(“男”) ? “先生” : “女士”;OUT:while (true) {System.out.println(“ list.get(index).getName() gender 请选择所要办理的业务”);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(“请选择”);choice2 sc.nextInt();switch (choice2){case 1,2,3,5:business(choice2,list.get(index));break;case 4:transfer(index);break;case 7:System.out.println(“你确定要注销账户吗 y/n”);sure sc.next();if(sure.length() 1 sure.contains(“y”)){if(list.get(index).getBalance() 0) {list.remove(index);System.out.println(“账户已注销”);break OUT;}else {System.out.println(“此账户还有余额无法注销”);break;}}else if (sure.length() 1 sure.contains(“n”)){break ;}else {System.out.println(“输入有误已帮您退回业务界面”);break;}case 6:System.out.println(“你确定要退出吗 y/n”);sure sc.next();if(sure.length() 1 sure.contains(“y”)){break OUT;}else {break;}default:System.out.println(“输入有误请重新输入”);break;}}break;case 2:account();continue;default:System.out.println(“输入有误请重新输入”);continue;}}}//系统开户的方法public void account(){ATMSystem user new ATMSystem();//定义ATMSystem的变量一定要放在方法内部否则多次开户会覆盖原来的数据System.out.println(“系统开户”);//输入账户名System.out.println(“请您输入账户名”);String name sc.next();user.setName(name);//输入性别并判断while (true) {System.out.println(“请输入您的性别”);String gender sc.next();if(gender.length() 1 (gender.contains(“男”) || gender.contains(“女”))){user.setGender(gender);break;}else{System.out.println(“您输入的性别有误”);}}//输入密码并确认while (true) {System.out.println(“请您输入账户密码”);int password sc.nextInt();System.out.println(“请您确认密码”);int repassword sc.nextInt();if(password repassword){user.setPassword(password);break;}else {System.out.println(“您输入的密码不一致!”);}}//输入取现限额System.out.println(“请您输入账户每次的取现限额(最好为整)”);int quota sc.nextInt();user.setQuota(quota);//随机生成卡号String card “”;for (int i 0; i 8; i) {card r.nextInt(10);}user.setCard(card);System.out.println(“您的卡号为” card “请牢记”);list.add(user);System.out.println(“开户成功”);}//系统登录方法public int login(){while (true) {System.out.println(“系统登入”);System.out.println(“请输入卡号”);String recard sc.next();for (int i 0; i list.size(); i) {if(list.get(i).getCard().equals(recard)){String gender list.get(i).getGender().equals(“男”) ? “先生” : “女士”;while (true) {System.out.println(“请输入密码”);int repassword sc.nextInt();if(list.get(i).getPassword() repassword){System.out.println(“您已成功登入” list.get(i).getName() gender “卡号为” list.get(i).getCard());return i;}else{System.out.println(“你输入的密码有误”);}}}}System.out.println(“系统中没有该卡号”);}}//用户登录后的 查询、存款、取款、修改密码 的业务方法public void business(int choice, ATMSystem index){double money;int password;switch (choice) {case 1://查询账户System.out.println(“卡号” index.getCard());System.out.println(“户主” index.getName());System.out.println(“性别” index.getGender());System.out.println(“余额” index.getBalance());System.out.println(“限额” index.getQuota());break;case 2://存款System.out.println(“请您输入存款数额”);money sc.nextDouble();index.setBalance(index.getBalance() money);System.out.println(“存款成功你当前的余额为” index.getBalance());break;case 3://取款while (true) {System.out.println(“当前余额为” index.getBalance() “限额为” index.getQuota());System.out.println(“请输入取款金额”);money sc.nextDouble();if (money index.getQuota()) {if (money index.getBalance()) {index.setBalance(index.getBalance() - money);System.out.println(“取款成功当前余额为” index.getBalance() “请拿好现金!”);break;} else {System.out.println(“对不起余额不足”);continue;}} else {System.out.println(“对不起所取额度大于限额”);continue;}}break;case 5:while (true) {System.out.println(“请输入新的密码”);password sc.nextInt();System.out.println(“请确认新的密码”);int repassword sc.nextInt();if (password repassword) {index.setPassword(password);System.out.println(“密码修改完成”);break;} else {System.out.println(“您输入的密码不一致”);continue;}}break;}}//转账方法public void transfer(int index){String card;String restart;String name “”;String start “”;double money;int local 0;if(list.size() 2){if(list.get(index).getBalance() ! 0){OUT1:while (true) {System.out.println(“请输入对方账户的卡号”);card sc.next();for (int i 0; i list.size(); i) {if (list.get(i).getCard().equals(card) i ! index) {local i;break OUT1;}}if (local 0) {System.out.println(“系统中没有该卡号”);continue OUT1;}}String gender list.get(local).getGender().equals(“男”) ? “先生” : “女士”;name list.get(local).getName();start list.get(local).getName().charAt(0);//此处的start不能进入循环倘若姓氏输入有误就会使start再加一次姓氏导致连环错String rename name.replace(start, “*”);OUT2 :while (true) {System.out.println(“请输入[” rename gender “]的姓氏”);restart sc.next();if (start.equals(restart)) {while (true) {System.out.println(“请您输入转账金额您的余额为” list.get(index).getBalance() “,限额为” list.get(index).getQuota());money sc.nextDouble();if (money list.get(index).getQuota()) {if (money list.get(index).getBalance()) {list.get(index).setBalance(list.get(index).getBalance() - money);list.get(local).setBalance(list.get(local).getBalance() money);System.out.println(“转账成功当前余额为” list.get(index).getBalance());break OUT2;} else {System.out.println(“对不起余额不足”);continue;}} else {System.out.println(“对不起所取额度大于限额”);continue;}}} else {System.out.println(“你输入的信息有误”);continue OUT2;}}} else {System.out.println(“您的余额为0无法转账”);}} else {System.out.println(“当前系统中不足2个账户请去开户吧。”);}}}③main方法package com.itheiama.ATMsystem;public class MainInterface {public static void main(String[] args) {ATMSystemOperator list new ATMSystemOperator();}}运行部分截图所遇问题在编写过程中出现过以下问题1️⃣在编写隐藏账户户主的姓氏并要求确认时因死循环中嵌套switch 其中一个case分支又嵌套一个新的死循环加for循环导致如果姓氏输入错一次定义存放姓氏的变量start就会再加一次姓氏的内容导致后续出错。正确方法为拆开为两个独立循环将中间的内容放在循环外部避免出错。2️⃣在编写系统开户方法的时候并没有将ATMSystem user new ATMSystem放在方法内部到导致当开第二个账户时虽然账户地址会交给集合但其内容会将第一个账户的信息覆盖导致虽然有多个地址指向不同对象但对象的数据是一致的无法进行转账.
项目实现:ATM系统
ATM模拟系统项目题目要求开发一个控制台ATM模拟系统实现以下功能①主界面需要用户登录与用户开户两个功能。②开户功能输入姓名、性别男/女设置密码并确认设置取现限额系统自动生成8位随机卡号账户存入系统③ 登录功能若系统中没有开户则不允许登录输入卡号和密码验证登录成功后进入业务界面④业务功能查询账户显示卡号、姓名、性别、余额、限额存款输入金额更新余额取款检查余额和限额转账1验证对方卡号2隐藏此账户户主的姓氏请求确认3金额不能超限额/余额修改密码加确认退出返回主界面注销账户余额必须为0时才可注销且要确认是否注销··设计思路账户有卡号、姓名、性别、余额、限额所以要用面向对象编程创建实体类来封装信息又因为对象数目不固定所以要用集合来存储对象的地址。··代码实现①实体类package com.itheiama.ATMsystem;//系统的实体类public class ATMSystem {private String name;//账户名private String card;//卡号private int password;//密码private String gender;//性别private double balance;//余额private double quota;//限额public ATMSystem() {}public ATMSystem(String name, String card, int password, String gender, double balance, double quota) {this.name name;this.card card;this.password password;this.gender gender;this.balance balance;this.quota quota;}public String getName() {return name;}public void setName(String name) {this.name name;}public String getCard() {return card;}public void setCard(String card) {this.card card;}public int getPassword() {return password;}public void setPassword(int password) {this.password password;}public String getGender() {return gender;}public void setGender(String gender) {this.gender gender;}public double getBalance() {return balance;}public void setBalance(double balance) {this.balance balance;}public double getQuota() {return quota;}public void setQuota(double quota) {this.quota quota;}}②ATM系统方法类package com.itheiama.ATMsystem;import java.util.ArrayList;import java.util.Random;import java.util.Scanner;//ATM系统方法类public class ATMSystemOperator {private ArrayList list new ArrayList();//定义一个实体类的集合private int choice1;private int choice2;private String sure;Scanner sc new Scanner(System.in);Random r new Random();//构造器用于创建系统界面public ATMSystemOperator() {while (true) {System.out.println(“欢迎来到ATM系统”);System.out.println(“1,用户登录”);System.out.println(“2用户开户”);System.out.println(“请选择你的操作”);choice1 sc.nextInt();switch (choice1) {case 1:if (list.size() 0) {System.out.println(“当前系统无账户无法登录”);continue;}int index login();String gender list.get(index).getGender().equals(“男”) ? “先生” : “女士”;OUT:while (true) {System.out.println(“ list.get(index).getName() gender 请选择所要办理的业务”);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(“请选择”);choice2 sc.nextInt();switch (choice2){case 1,2,3,5:business(choice2,list.get(index));break;case 4:transfer(index);break;case 7:System.out.println(“你确定要注销账户吗 y/n”);sure sc.next();if(sure.length() 1 sure.contains(“y”)){if(list.get(index).getBalance() 0) {list.remove(index);System.out.println(“账户已注销”);break OUT;}else {System.out.println(“此账户还有余额无法注销”);break;}}else if (sure.length() 1 sure.contains(“n”)){break ;}else {System.out.println(“输入有误已帮您退回业务界面”);break;}case 6:System.out.println(“你确定要退出吗 y/n”);sure sc.next();if(sure.length() 1 sure.contains(“y”)){break OUT;}else {break;}default:System.out.println(“输入有误请重新输入”);break;}}break;case 2:account();continue;default:System.out.println(“输入有误请重新输入”);continue;}}}//系统开户的方法public void account(){ATMSystem user new ATMSystem();//定义ATMSystem的变量一定要放在方法内部否则多次开户会覆盖原来的数据System.out.println(“系统开户”);//输入账户名System.out.println(“请您输入账户名”);String name sc.next();user.setName(name);//输入性别并判断while (true) {System.out.println(“请输入您的性别”);String gender sc.next();if(gender.length() 1 (gender.contains(“男”) || gender.contains(“女”))){user.setGender(gender);break;}else{System.out.println(“您输入的性别有误”);}}//输入密码并确认while (true) {System.out.println(“请您输入账户密码”);int password sc.nextInt();System.out.println(“请您确认密码”);int repassword sc.nextInt();if(password repassword){user.setPassword(password);break;}else {System.out.println(“您输入的密码不一致!”);}}//输入取现限额System.out.println(“请您输入账户每次的取现限额(最好为整)”);int quota sc.nextInt();user.setQuota(quota);//随机生成卡号String card “”;for (int i 0; i 8; i) {card r.nextInt(10);}user.setCard(card);System.out.println(“您的卡号为” card “请牢记”);list.add(user);System.out.println(“开户成功”);}//系统登录方法public int login(){while (true) {System.out.println(“系统登入”);System.out.println(“请输入卡号”);String recard sc.next();for (int i 0; i list.size(); i) {if(list.get(i).getCard().equals(recard)){String gender list.get(i).getGender().equals(“男”) ? “先生” : “女士”;while (true) {System.out.println(“请输入密码”);int repassword sc.nextInt();if(list.get(i).getPassword() repassword){System.out.println(“您已成功登入” list.get(i).getName() gender “卡号为” list.get(i).getCard());return i;}else{System.out.println(“你输入的密码有误”);}}}}System.out.println(“系统中没有该卡号”);}}//用户登录后的 查询、存款、取款、修改密码 的业务方法public void business(int choice, ATMSystem index){double money;int password;switch (choice) {case 1://查询账户System.out.println(“卡号” index.getCard());System.out.println(“户主” index.getName());System.out.println(“性别” index.getGender());System.out.println(“余额” index.getBalance());System.out.println(“限额” index.getQuota());break;case 2://存款System.out.println(“请您输入存款数额”);money sc.nextDouble();index.setBalance(index.getBalance() money);System.out.println(“存款成功你当前的余额为” index.getBalance());break;case 3://取款while (true) {System.out.println(“当前余额为” index.getBalance() “限额为” index.getQuota());System.out.println(“请输入取款金额”);money sc.nextDouble();if (money index.getQuota()) {if (money index.getBalance()) {index.setBalance(index.getBalance() - money);System.out.println(“取款成功当前余额为” index.getBalance() “请拿好现金!”);break;} else {System.out.println(“对不起余额不足”);continue;}} else {System.out.println(“对不起所取额度大于限额”);continue;}}break;case 5:while (true) {System.out.println(“请输入新的密码”);password sc.nextInt();System.out.println(“请确认新的密码”);int repassword sc.nextInt();if (password repassword) {index.setPassword(password);System.out.println(“密码修改完成”);break;} else {System.out.println(“您输入的密码不一致”);continue;}}break;}}//转账方法public void transfer(int index){String card;String restart;String name “”;String start “”;double money;int local 0;if(list.size() 2){if(list.get(index).getBalance() ! 0){OUT1:while (true) {System.out.println(“请输入对方账户的卡号”);card sc.next();for (int i 0; i list.size(); i) {if (list.get(i).getCard().equals(card) i ! index) {local i;break OUT1;}}if (local 0) {System.out.println(“系统中没有该卡号”);continue OUT1;}}String gender list.get(local).getGender().equals(“男”) ? “先生” : “女士”;name list.get(local).getName();start list.get(local).getName().charAt(0);//此处的start不能进入循环倘若姓氏输入有误就会使start再加一次姓氏导致连环错String rename name.replace(start, “*”);OUT2 :while (true) {System.out.println(“请输入[” rename gender “]的姓氏”);restart sc.next();if (start.equals(restart)) {while (true) {System.out.println(“请您输入转账金额您的余额为” list.get(index).getBalance() “,限额为” list.get(index).getQuota());money sc.nextDouble();if (money list.get(index).getQuota()) {if (money list.get(index).getBalance()) {list.get(index).setBalance(list.get(index).getBalance() - money);list.get(local).setBalance(list.get(local).getBalance() money);System.out.println(“转账成功当前余额为” list.get(index).getBalance());break OUT2;} else {System.out.println(“对不起余额不足”);continue;}} else {System.out.println(“对不起所取额度大于限额”);continue;}}} else {System.out.println(“你输入的信息有误”);continue OUT2;}}} else {System.out.println(“您的余额为0无法转账”);}} else {System.out.println(“当前系统中不足2个账户请去开户吧。”);}}}③main方法package com.itheiama.ATMsystem;public class MainInterface {public static void main(String[] args) {ATMSystemOperator list new ATMSystemOperator();}}运行部分截图所遇问题在编写过程中出现过以下问题1️⃣在编写隐藏账户户主的姓氏并要求确认时因死循环中嵌套switch 其中一个case分支又嵌套一个新的死循环加for循环导致如果姓氏输入错一次定义存放姓氏的变量start就会再加一次姓氏的内容导致后续出错。正确方法为拆开为两个独立循环将中间的内容放在循环外部避免出错。2️⃣在编写系统开户方法的时候并没有将ATMSystem user new ATMSystem放在方法内部到导致当开第二个账户时虽然账户地址会交给集合但其内容会将第一个账户的信息覆盖导致虽然有多个地址指向不同对象但对象的数据是一致的无法进行转账.