Java simulation Bank Self-Service terminal system _java

Source: Internet
Author: User
Tags throw exception

A This system simulates the bank user to use the ATM machine to open accounts, inquires, the deposit, the withdrawal function, requests uses the Java language programming realization.

Description

1. For data entry exceptions, you can use the Java exception handling mechanism for processing.

2. The grading will be evaluated in a way that combines functional implementation with code standardization.

3. If you have questions about the project needs, you can contact me at any time by QQ message to consult.

4. National Day holiday period, every day teachers in the company on duty, October 4 is my company on duty, October 7 normal work, welcome everyone to the company to do the project.

Two Project Functional Requirements:

Project starts to run Show main Menu as:

Bank Self-Service terminal system

****************************

0.------Account

1.------Enquiries

2.------Deposits

3.------Withdrawals

4.------Exit

****************************

Please select the function you want to perform:

At this point, the user can choose the function to implement through the keyboard input, if the input is not 0,1,2,3,4, then the system prompts:

The menu you chose does not exist!

Please select again:

Require users to re-enter the data for menu selection!

When the user enters 0 o'clock, the query function is entered: System prompts:

****************************

You have chosen for the account opening function

Please enter your name:

At this point the user needs to enter the name, after entering the system prompts:

Please enter your ID number:

At this point, the user needs to enter 18 ID number, entered completed if the verification did not pass the request to continue to enter until the verification passed after the system prompts:

Please enter your password:

At this time the user needs to enter 6-digit pure digital password, input complete if the verification did not pass the request to continue to enter, verify the system prompts after passing:

Open account successfully, thank you for using!

Bank Self-Service terminal system

****************************

0.------Account

1.------Enquiries

2.------Deposits

3.------Withdrawals

4.------Exit

****************************

Please select the function you want to perform:

When the user enters 1 o'clock, the query function is entered: System prompts:

****************************

You select the Query function

Please enter the card number you want to inquire:

At this point the user needs to enter the query card number, the system to detect the card number, if the card number does not exist, then hint: you enter the card number does not exist, please re-enter:

Please enter the card number you want to inquire:

Requires that the card number be entered again, and when the user enters the correct card number, it prompts:

Please enter your password:

At this time the user needs to enter 6-digit pure digital password, input complete if the verification does not require continued input (up to 3), the system will display the current user account information and access to the main menu:

The account information you inquire for is:

******************************

Name, ID card number, amount.

Zhang 420106198410112062 111111 12800.0

Bank Self-Service terminal system

****************************

0.------Account

1.------Enquiries

2.------Deposits

3.------Withdrawals

4.------Exit

****************************

Please select the function you want to perform:

Enter the deposit function when the user enters 2 o'clock: System prompt:

****************************

The Deposit function you chose

Please enter the card number you want to deposit:

At this time the user needs to enter the deposit card number, the system to check the card number, if the card number does not exist, then hint:

The card number you entered does not exist, please re-enter:

Please enter the card number you want to deposit:

Requires that the card number be entered again, and when the user enters the correct card number, it prompts:

Please enter your password:

At this time the user needs to enter 6-digit pure digital password, input complete if the verification does not require continued input (up to 3), the system will display the current user account information and access to the main menu:

The account information you want to deposit is:

******************************

Name, ID card number, amount.

Zhang 420106198410112062 111111 12800.0

Please enter the amount you want to deposit:

The user is required to enter the amount of deposit, the system to determine the amount, if the input data is less than or equal to 0, then prompt:

The data you entered is invalid and the system will automatically exit! Thank you for using

Bank Self-Service terminal system

****************************

0.------Account

1.------Enquiries

2.------Deposits

3.------Withdrawals

4.------Exit

****************************

Please select the function you want to perform:

If the user enters the data legally, the system prompts the deposit to succeed and returns to the main menu:

Deposit success, thank you for using!

Bank Self-Service terminal system

****************************

0.------Account

1.------Enquiries

2.------Deposits

3.------Withdrawals

4.------Exit

****************************

Please select the function you want to perform:

The data will be stored in the user account, and if the user queries the data again, the amount of the account that has changed is visible. (Note: This system uses files for data storage, so if the user restarts the program, the data will be read from the file and reinitialized to memory!) This feature is selected to refer to the serialization and deserialization of objects or JSON)

When the user input 3 o'clock, then enter the withdrawal function: System prompts:

****************************

For withdrawal function, please enter the card number you want to withdraw:

At this time the user needs to enter the card number of the withdrawal, the system card number for detection, if the card number does not exist, then prompted:

The card number you entered does not exist, please re-enter:

Please enter the card number you want to withdraw:

Requires that the card number be entered again, and when the user enters the correct card number, it prompts:

Please enter your password:

At this time the user needs to enter 6-digit pure digital password, input complete if the verification does not require continued input (up to 3), the system will display the current user account information and access to the main menu:

The account information you want to withdraw is:

******************************

Name, ID card number, amount.

Zhang 420106198410112062 111111 12800.0

Please enter the amount you want to withdraw:

At this time, users are required to enter the amount of withdrawals, the system to determine the amount, if the input data is less than 0 or greater than the total account amount, then hint:

The data you entered is invalid and the system will automatically exit! Thank you for using

Bank Self-Service terminal system

****************************

0.------Account

1.------Enquiries

2.------Deposits

3.------Withdrawals

4.------Exit

****************************

Please select the function you want to perform:

If the user enters the data legally, the system prompts for a successful withdrawal and returns to the main menu:

Withdrawal success, thank you for using!

Bank Self-Service terminal system

****************************

0.------Account

1.------Enquiries

2.------Deposits

3.------Withdrawals

4.------Exit

****************************

Please select the function you want to perform:

The data will be deducted from the user account, and if the user is queried again, the amount of the account that has been changed can be seen.

When the user enters 4 o'clock, the system exits.

Three Design Requirements

(i) package one: Com.bank.unionpay for UnionPay, added under the package:

Represents the interface of a bank card that contains an abstract method of checking balances, deposits, withdrawals, and so on.
Represents an abstract class of ATM machines, using the bank card type Object as a property or parameter, to realize the query balance, deposit, withdrawal and other instance methods, add account for abstract method.
Enumeration type representing four major banks: including Abc,icbc,ccb,boc; on behalf of ABC, ICBC, CCB, BOC.

(ii) package two: Com.bank.abc said ABC, under the package added:

Defines a bank class in single mode, containing attributes: Bank type (enum type, constant =ABC), bank name (String), bank card list (collection), and so on.
Define the implementation class for the bank card-card, including attributes: Bank type (enumeration type =ABC), name, ID number, card number, password, balance, realization of the balance of inquiries, deposits, withdrawals and other methods.

Define the subclasses of ATM, including attributes: Bank type (enumeration type, constant =ABC), to implement the method of opening an account, in which: only card, card number 6-digit random number, automatically generated. The newly opened bank card is added to the bank card list.

Define subclass of card-credit card, add attribute: Overdraft limit, rewrite withdrawal method, control maximum withdrawal amount cannot be greater than balance + overdraft limit.

(iii) package Three: Com.bank.test represents the test, under the package to add a test class with the main method to achieve the project requirements of the simulation ATM function.

The following features are selected:

In the form of a single state of ICBC, in the test class by default to add more than a bank card, on ABC's ATM machine to achieve cross query and deposit and withdrawal function.

Package One: Com.bank.unionpay

1, bank card abstract class

Package com.bank.unionpay;
Public interface Yinhangka {public
void Cun ();
public void Qu ();
public void Getyu ();
}

2, enumerating bank types

Package com.bank.unionpay;
public enum Yinhang {
ABC ("ABC"), ICBC ("Business"), CCB ("CCB"), BOC ("BOC");
Private final String Yinhang;
Privatisation construction Method
private Yinhang (String Yinhang)
{
this.yinhang=yinhang;
}
Public String getname ()
{return
This.yinhang
}
}

3,atm class

Package com.bank.unionpay;
Import Com.bank.abc.Yinhanglei;
Public abstract class ATM {
private yinhanglei YHL//Bank class properties
private double yue;//variable Yue public
double Getyue () {return
yue;
}
public void Setyue (double yue) {
This.yue = Yue;
}
Query method public
void Yue ()
{
System.out.println ("Balance on card is:" +this.yue);
}
Deposit method Public
void Cun (double cun)
{
if (cun<0)
{
System.out.println ("incorrect input");
}
else
{
this.yue+=cun;
System.out.println ("The balance on the card is:" +this.yue);
}
Withdrawal method public
void Qu (double qu)
{
if (Qu>this.yue)
{
System.out.println ("Insufficient balance");
}
else 
{
this.yue-=qu;
System.out.println ("The balance on the card is:" +this.yue);
}
Define account opening abstract method public abstract
void Kaihu ();
}

4, Main interface class

Package com.bank.unionpay;
Import java.util.ArrayList;
Import java.util.List;
Import Java.util.Scanner;
public class Zujiemian {public
void Zhujiemian ()
{
System.out.println ("Bank Self-Service terminal system");
System.out.println ();
System.out.println ("****************************");
System.out.println ();
List<string> li=new arraylist<string> ();
Li.add ("account opening");
Li.add ("Query");
Li.add ("deposit");
Li.add ("withdrawal");
Li.add ("Exit");
for (int i=0;i<5;i++)
{
System.out.println (i+ "-----" +li.get (i));
}
System.out.println ();
System.out.println ("****************************");
System.out.println ();
SYSTEM.OUT.PRINTLN ("Please select the function you want to perform:");
}

Package Two: COM.BANK.ABC

1,ATM2 account Opening Class

Package com.bank.abc;
Import Java.util.Random;
Import Java.util.Scanner;
Import Com.bank.unionpay.ATM;
Import Com.bank.unionpay.Yinhang; 
public class ATM2 extends atm{private Yinhang yhl=yinhang.abc;
@Override public void Kaihu () {//Account opening method//Enter name Cuxuka cxk=new Cuxuka (); try{Scanner sc1=new (Scanner system.in);
System.out.println ("Please enter your name:");
String St=sc1.nextline ();
Cxk.setname (ST);
Enter your ID card System.out.println ("Please enter your ID number:");
for (int ig=0;ig>=0;ig++) {Scanner sc2=new Scanner (system.in);
String Str=sc2.nextline ();
String st1= "\\d{15}|\\d{17}[\\dxx]";
if (Str.matches (ST1)) {Cxk.setshenfen (str); break;} else {System.out.println ("The ID number entered is not a 18-digit identity number");}
Set the account password System.out.println ("Please enter your password:");
for (int ig=0;ig>=0;ig++) {Scanner sc3=new Scanner (system.in);
String Pass=sc3.nextline ();
String mm= "\\d{6}";
if (pass.matches (mm)) {Cxk.setpassword (pass), break;} else {System.out.println ("Please enter the correct 6-digit password");}
Generate 6-digit card number Random a=new Random ();
Int[] Ch=new int[6]; StringBuilder str=newStringBuilder ();
String s;
for (int i=0;i<6;i++) {ch[i]=a.nextint (9),} for (Integer c:ch) {str.append (c);} s=str.tostring ();
Cxk.setcard (s);
Import the generated data into the bank card list List Yinhanglei.getyinhanglei (). List.add (Cxk.getcard ());
Import the generated data into the bank card map List Yinhanglei.getyinhanglei (). Map.put (Cxk.getcard (), cxk);
System.out.println ("Your new card number is:" +cxk.getcard ());
System.out.println ("Successful account opening, thank you for using");
}catch (Exception e) {System.out.println ("incorrect input");} }

2, card class

Package com.bank.abc;
Import Java.util.Scanner;
Import Com.bank.unionpay.Yinhang;
Import Com.bank.unionpay.Yinhangka; public class Cuxuka implements Yinhangka {//card property private Yinhang Yinhang; private string name; private String Shenfen p
Rivate String Card;
private String password;
private double balance;
Generate ToString ();  @Override public String toString () {return "name =" + name + "\t\n" + "identity card =" + Shenfen + "\t\n" + "card number =" +card + "\t\n" + "Account amount ="
+ balance; ///Set the property to a Get set setting public Yinhang Getyinhang () {return YINHANG=YINHANG.ABC.} public String GetName () {return name;} PU Blic void SetName (string name) {this.name = name;} public String Getshenfen () {return shenfen;} public void Setshenfen (String Shenfen)
{This.shenfen = Shenfen;} public string Getcard () {return card.} public void Setcard (String card) {this.card = card;} public string GetPassword ( 
{return password} is public void SetPassword (String password) {this.password = password;} public double getbalance () { RetuRN balance; The public void setbalance (double balance) {this.balance = balance}//deposit method @Override public void Cun () {Cuxuka cu1=new C
Uxuka ();
Cu1.chaxun ();
Scanner sc2=new Scanner (system.in);
System.out.println ("Please enter the amount you want to deposit:");
Double cun=sc2.nextdouble (); Implementation Deposit method if (cun<0) {System.out.println ("The data you entered is invalid, the system will automatically exit!")
Thank you for using ");
else {this.balance+=cun;
Yinhanglei.getyinhanglei (). Map.get (Cu1.card). Setbalance (balance);
System.out.println ("Deposit succeeded, Remaining Amount" +yinhanglei.getyinhanglei (). Map.get (Cu1.card). GetBalance ());
}///Query method public void Chaxun () {while (true) {try{Scanner sc=new Scanner (system.in);
System.out.println ("Please enter the card number you want to inquire:");
String S=sc.nextline ();
Traverse Yinhanglei's Map collection for (String Temp:Yinhanglei.getYinhangLei (). Map.keyset ()) {if (S.equals (temp)) {this.card=s;}}
if (s.equals)//Verify card number {int i=0;
System.out.println ("Please enter your password:");
while (true) {Scanner sc1=new Scanner (system.in);
String St1=sc1.nextline (); if (St1.equals (Yinhanglei.getyinhanglei (). Map.get (s). GetPassword ())) {System.ouT.println ("The account information you inquire for is:");
System.out.println ();
System.out.println ("******************************");
System.out.println ();
SYSTEM.OUT.PRINTLN ("Name ID card number");
System.out.println ();
System.out.println (Yinhanglei.getyinhanglei (). Map.get (s));
Break
else {i++ if (i==3) {System.out.println ("Password input error exceeds 3 times"); break;} else {System.out.println ("password entered incorrectly");}} else {System.out.println ("card number entered incorrectly please confirm");}
catch (Exception e) {System.out.println ("incorrect input");} break;
}//Withdrawal method operation @Override public void Qu () {Cuxuka cu=new Cuxuka (); Cu.chaxun ();
Scanner sc1=new Scanner (system.in);
System.out.println ("Please enter the amount of money you want to withdraw:");
Double qu=sc1.nextdouble ();
Realization of the Withdrawal method if (qu<balance) {this.balance-=qu;
Yinhanglei.getyinhanglei (). Map.get (Cu.card). Setbalance (balance);
System.out.println ("Withdrawal success, Remaining Amount:" + yinhanglei.getyinhanglei (). Map.get (Cu.card). GetBalance ()); else if (qu<0) {System.out.println ("The data you entered is invalid, the system will automatically exit!")
Thank you for using ");;
else {System.out.println ("insufficient balance");} @Override public void Getyu () {//Balance calculation CuxukA cu=new Cuxuka ();
System.out.println ("Remaining Amount" +cu.getbalance ()); }
}

3, single case mode bank class

Package com.bank.abc;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;
Import Com.bank.unionpay.Yinhang;
public class Yinhanglei {
//bank class attribute
private Yinhang yinhang=yinhang.abc;
private String name;
Public list<string> list=new arraylist<> ();
Public map<string, cuxuka> map=new hashmap<> ();
Privatisation construction Method
private Yinhanglei () {
super ();
}
private static Yinhanglei bank=new Yinhanglei ();
public static Yinhanglei Getyinhanglei ()
{return
bank;
}
}

4, credit card category

Package com.bank.abc;
The public class Xinyongka extends Cuxuka {
//constructs its own properties
private double Touzhi;
Public double Gettouzhi () {return
Touzhi;
}
public void Settouzhi (double touzhi) {
This.touzhi = Touzhi;
}
Rewrite the withdrawal method public
void Qu (double qu) {
//Implement withdrawal Method
if ((Touzhi+getbalance ()) >=qu)
{
System.out.println ("Overdraft Amount" + (Qu-getbalance ()));;
}
else
{
System.out.println ("Cannot withdraw more than maximum overdraft limit");;}
}

Package Three: Com.bank.test

1, Test class

Package com.bank.test;
Import java.util.ArrayList;
Import java.util.List;
Import Java.util.Scanner;
Import com.bank.abc.ATM2;
Import Com.bank.abc.Cuxuka;
Import Com.bank.unionpay.ATM;
Import Com.bank.unionpay.Zujiemian;  public class Test1 {public static void main (string[] args) {//main interface production Cuxuka cxk=new Cuxuka ();//Instantiate main interface Zujiemian Zjm=new
Zujiemian ();
Throw exception try{//Create Dead loop for (int i=0;i>=0;i++) {Zjm.zhujiemian ();
Scanner sc=new Scanner (system.in);
int In=sc.nextint (); Determine if the input number conforms to the interface number if (in==0| | in==1| | in==2| | in==3| |
in==4) {//Account opening function if (in==0) {ATM2 atm2=new ATM2 (); Atm2.kaihu ();
System.out.println ("****************************");
System.out.println ("You selected for the opening function");
System.out.println ();
Continue
}//Query function if (in==1) {System.out.println ("****************************");
SYSTEM.OUT.PRINTLN ("You select for query function");
Cxk.chaxun ();
Continue
}//Deposit function if (in==2) {System.out.println ("****************************");
System.out.println ("You selected for the deposit function");
Cxk.cun ();
Continue }//Withdrawal function if (in==3) {System.out.prinTLN ("****************************");
System.out.println ("You selected for the withdrawal function");
Cxk.qu ();
Continue }//Exit Function if (in==4) {System.out.println ("Thank you for using!")
");
Break }//does not conform to the menu content print else {System.out.println ("Your selected menu does not exist!")
");
}
} 
The exception throws print}catch (Exception e) {System.out.println ("incorrect input");} }
}

Results:

The above is a small series to introduce the Java Simulation Bank Self-Service terminal system, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.