Java to write a simple ATM access system _java

Source: Internet
Author: User
Tags readline stub

Novice practicing must ~

The password account is:

Create account class First:

Copy Code code as follows:

Package CN. Atm;
/**
* @author Me Yes
*/
Import java.io.*;
Import Com.project.project;
public class Account {
Private String Number=null;
Private String Name=null;
Private String Password=null;
Private double money=0.0;
Public account (String number,string name,string password,double) {
This.number=number;
This.name=name;
This.password=password;
This.money=money;
}
Public String GetNumber () {
return number;
}
public void Setnumber (String number) {
This.number = number;
}
Public String GetName () {
return name;
}
public void SetName (String name) {
THIS.name = name;
}
Public String GetPassword () {
return password;
}
public void SetPassword (String password) {
This.password = password;
}
Public double Getmoney () {
return money;
}
public void Setmoney (double) {
This.money = money;
}
protected void Sub_balance (double mon) {
Money-=mon;
}
protected void Add_balancen (double mon) {
Money+=mon;
}
}

Then set up the action class:

It contains various methods of operation:

Copy Code code as follows:

Package CN. Atm;
/**
* @author Me Yes
*/
Import java.io.*;

Import Com.project.project;
public class ATM {
Account Act;

Public ATM () {
Act=new account ("0000", "test", "0000", 2000);
}
/************* Welcome Interface *********************/
protected void Welcome () {
String str= "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
System.out.print (str+ "\ n");
System.out.print (
"1. Withdrawal" + "\ n" +
"2. Query" + "\ n" +
"3. Deposit" + "\ n" +
"4. Exit" + "\ n"
);
System.out.print (str+ "\ n");
}
/************ Landing System ********************/
protected void Load_sys () throws exception{
String card,pwd;
int counter=0;
BufferedReader br=new BufferedReader (New InputStreamReader (system.in));
do{
System.out.println ("Please enter your card number");
Card=br.readline ();
System.out.println ("Please enter your password");
Pwd=br.readline ();
if (!isright (card,pwd)) {
System.out.println ("Your card number or password is incorrect");
counter++;
}
else {
Welcome ();
Sysopter ();
}
}while (counter<5);
System.exit (1);
}
/********** system operation prompts ******************/
protected void Sysopter () throws Exception {
int num;
BufferedReader br=new BufferedReader (New InputStreamReader (system.in));
SYSTEM.OUT.PRINTLN ("Please select the item you want to operate (1--4)");
Num=br.read ();
Switch (num) {
Case 49:
GetBalance ();
Break
Case 50:
Inqu_iofo ();
Break
Case 51:
Addbalance ();
Break
Case 52:
Exit_sys ();
Break
}
}
/********** Information Query *******************/
protected void Inqu_iofo () throws exception{
TODO auto-generated Method Stub
String str= "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
System.out.print (str+ "\ n");
System.out.print (
"Account" +act.getnumber () + "\ n" +
"Name" +act.getname () + "\ n" +
"Balance" +act.getmoney () + "\ n" +
Str+ "\ n"
);
Sysopter ();
}

/********** Deposit ******************/
public void Addbalance () throws exception{
TODO auto-generated Method Stub
String str=null,str1;
BufferedReader br=new BufferedReader (New InputStreamReader (system.in));
do {
System.out.println ("Please enter the number of deposits");
Str=br.readline ();
Double qu=double.valueof (str). Doublevalue ();
Act.add_balancen (QU);
System.out.println ("The deposit is successful, your account balance is" +act.getmoney ());
Welcome ();
Sysopter ();
} while (true);
}
/********** withdrawal ********************/
public void GetBalance () throws exception{
TODO auto-generated Method Stub
String str=null,str1;
BufferedReader br=new BufferedReader (New InputStreamReader (system.in));
do {
System.out.println ("Please enter the number of withdrawals");
Str=br.readline ();
Double qu=double.valueof (str). Doublevalue ();
if (Qu>act.getmoney ()) {
SYSTEM.OUT.PRINTLN ("Please re-enter the balance insufficient");
}
else {
Act.sub_balance (QU);
SYSTEM.OUT.PRINTLN ("Withdraw successfully your account balance is not" +act.getmoney ());
Welcome ();
Sysopter ();
}
} while (true);
}
/********* Exit ******************/
protected void Exit_sys () {
TODO auto-generated Method Stub
SYSTEM.OUT.PRINTLN ("Safe exit!") ");
System.exit (1);
}

/********** card number and password are correct ********************/
Protected Boolean Isright (string card, string pwd) {
TODO auto-generated Method Stub
if (Act.getnumber (). Equals (Card) &&act.getpassword (). Equals (pwd)) {
return true;
} else {
return false;
}

}
public static void Main (string[] args) throws Exception {
ATM Atm=new ATM ();
Atm. Welcome ();
Atm. Load_sys ();
}
}

Code for reference only

The results of the operation are as follows

All right, buddy, you can make an ATM out of your own ^_^.

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.