Introduce a,

The function points of the ATM simulation program are as follows:

Graphical user interface is required: The main interface allows you to enter the administrator interface, user interface, system setting interface, and exit the main interface allows you to start the software and enter user mode or system management mode. To enter the system management mode, you need to enter the administrator account and password to view the details of recent fund incomings and exits of this ATM, the historical records and details of all accounts operated on this ATM, and export all records to excel files. Into the user account and password login screen, when entering a given card number and password (initial card number 16 and password 6th), contrast system storage account and password are correct, can log on to the ATM teller machine system, the error number for 3 times, the locking account cannot continue operating, accumulative total 3 is locked, need administrator account to complete the unlock operation.  Users can operate according to the following rules: 1. Query the balance: The initial balance is 100000 YUAN; 2. ATM withdrawal: The amount of each withdrawal shall be a multiple of 100, and the total amount shall not exceed 5000 YUAN. The amount of withdrawal shall not be overdrawn. 3. ATM deposit: negative deposit is not allowed, and the deposit is required to be an integer multiple of 100; 4. ATM transfer: transfer money to the specified bank account (saved in the system) by the login user. If the bank card does not exist, the input error of the bank card number will be prompted, and "transfer success" will be prompted if the transfer is successful. 5, historical transaction records query: can display more than 20 transaction records, transaction records can be imported from the file, also can export records to the file; 6. Change the password: The new password contains at least six characters. The password can be changed only when the old password is correct and the new password meets the requirements and is entered the same twice. 7. Return card: Click Repel card to return to the login interface.Copy the code

Second, software architecture

Use Java GUI to develop system interface

Export TXT files to the system directory using File

Three, installation tutorial

Computer installation JDK, set the environment variables double-click to run

4. System demonstration

Login function on the main screen

Administrator background

User main interface

withdrawals

Query transaction Records

transfer

How do you do that? First, we define a User class User, at the same time according to the requirements of the design of the attributes (I did not use the camel name, not standard). Since one person can have multiple cards and the card number cannot be repeated, I define a set to store the card number. The rest of the names and passwords are defined as strings, and the rest are defined as double (you can use BigDecimal if you don’t mind). It then automatically generates the constructor and Getter and setter methods

import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.TreeSet; Public class User {// User class User private Set<Integer> Set =new TreeSet<Integer>(); // Private member variable -- card number private String name; // Private String miMa; // Private variable password private double yuE; Public User(int cardNum, String name, String miMa) {this.set.add(cardNum); this.name = name; this.miMa = miMa; this.yuE = 0; } public boolean hasNum(int CardNum) { Iterator<Integer> iter=set.iterator(); while(iter.hasNext()){ int in=iter.next(); if(in==CardNum){ return true; } } return false; } public void setCardNum(int cardNum) { this.set.add(cardNum); } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getMiMa() { return miMa; } public void setMiMa(String miMa) { this.miMa = miMa; } public double getYuE() { return yuE; } public void setYuE(double yuE) { this.yuE += yuE; } public void setYuE2(double yuE) { this.yuE -= yuE;Copy the code

Then define a class write method to implement the ATM function, because ATM does not provide account opening function, so HERE I just write a simple create method, and then implement the withdrawal, deposit, query method.

package com.baidu.HomeWork.Work16; import java.util.InputMismatchException; import java.util.Iterator; import java.util.LinkedList; import java.util.Scanner; public class Method { static LinkedList<User> userList = new LinkedList<User>(); Scanner scan = new Scanner(System.in); double mon; static int cardNum = 100000; static int Card = 0; Void saveMon(int Card, int I) { Loop variable I * * * * * * * * */ system.out.println (" Your name is "+ userlist.get (I).getName()); System.out.println(" Please input the deposit amount "); try { mon = scan.nextDouble(); } catch (InputMismatchException e) { e.printStackTrace(); } catch (RuntimeException e) { e.printStackTrace(); } userList.get(i).setYuE(mon); System.out.println(" store "+ mon +" yuan "); System.out.println(" Now your account balance "+ userlist.get (I).getyue ()); } void getMon(int Card, int I) { Loop variable I * * * * * * * * */ system.out.println (" Your name is "+ userlist.get (I).getName()); System.out.println(" Please input the withdrawal amount "); try { mon = scan.nextDouble(); } catch (InputMismatchException e) { e.printStackTrace(); } if (mon < userList.get(i).getYuE()) { userList.get(i).setYuE2(mon); System.out.println(" fetch "+ mon + "); System.out.println(" Now your account balance "+ userlist.get (I).getyue ()); }} void cha(int Card, int I) { Loop variable I * * * * * * * * */ system.out.println (" Your name is "+ userlist.get (I).getName()); System.out.println(" Now your account balance "+ userlist.get (I).getyue ()); } void creatUser() {/* Create user () {* * * * * * * * */ String name = ""; String miMa = ""; System.out.println(" Please enter your name "); try { name = scan.next(); } catch (RuntimeException e) { e.printStackTrace(); } system.out. println(" Please enter password "); try { miMa = scan.next(); } catch (RuntimeException e) { e.printStackTrace(); } userList.add(new User(++cardNum, name, miMa)); System.out.println(" your id is :" + cardNum); } int dengLu() {tag = true; String miMa; System.out.println(" Please enter account number "); try { Card = scan.nextInt(); } catch (InputMismatchException e) { e.printStackTrace(); } catch (RuntimeException e) { e.printStackTrace(); } system.out. println(" Please enter password "); miMa = scan.next(); for (int i = 0; i < userList.size(); i++) { if (userList.get(i).hasNum(Card)) { if (userList.get(i).getMiMa().equals(miMa)) { return i; } else {system.out.println (" password error "); break; }} else {}} system.out.println (); return -2;Copy the code

Finally, define a linked list in the main class to store users, write a simple menu, put the second file into it, and the ATM is ready.

package com.baidu.HomeWork.Work16; import java.util.InputMismatchException; import java.util.LinkedList; import java.util.Scanner; public class GetMonMachine { static int num = 0; static boolean tag = true; static boolean tag_1 = true; static Scanner scan = new Scanner(System.in); static Method gm = new Method(); public static void main(String[] args) { gm.creatUser(); While (tag) {// Main menu int num; if ((num = gm.dengLu()) ! = -2) { System.out.println("1. Deposits "); System. The out. Println (" 2. "); System.out.println("3. System.out.println("4. int scan_num = 4; try { scan_num = scan.nextInt(); } catch (InputMismatchException e) {system.out.println (" input invalid "); e.printStackTrace(); } switch (scan_num) {// Select case 1: gm.saveMon(method. Card,num); break; case 2: gm.getMon(Method.Card,num); break; case 3: gm.cha(Method.Card,num); break; case 4: tag = false; break; Default: system.out.println (" input error, please re-enter "); break;Copy the code

Finally, add a try{}catch(){} where the input is to handle any exceptions that might occur.

conclusion

The end result is a set of operations that can’t be done without Java, and you have to keep learning if you want to keep moving forward. I recently put together a comprehensive Java programmer learning kit that I hope will help you find a good job and save you the time you spend searching online. In order to better help you learn, the following sorted out 2021 JAVA learning materials, including JAVA core knowledge points, learning topics and 2021 the latest Internet real questions, e-books, etc., for want to learn JAVA or want to change careers friends, college students are very practical. Collection of the latest Java learning materials in 2021

Content covers: Java, MyBatis, ZooKeeper, Dubbo, Elasticsearch, Memcached, Redis, MySQL, Spring, SpringBoot, SpringCloud, RabbitMQ, Kafka, Linux and other technology stacks.