A must-have for beginners~
The password account is:
First create the account class:
Copy the code code as follows:
package cn.Atm;
/**
* @author Oh my
*/
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 money){
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 money) {
this.money = money;
}
protected void sub_Balance(double mon) {
money-=mon;
}
protected void add_Balancen(double mon) {
money+=mon;
}
}
Then create an operation class:
It contains various operation methods:
Copy the code code as follows:
package cn.Atm;
/**
* @author Oh my
*/
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");
}
/************Login 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 tips******************/
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 deposit amount");
str=br.readLine();
double qu=Double.valueOf(str).doubleValue();
act.add_Balancen(qu);
System.out.println("The deposit was successful, your account balance is "+act.getMoney());
Welcome();
SysOpter();
} while (true);
}
/**********Withdraw************************/
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 withdrawal amount");
str=br.readLine();
double qu=Double.valueOf(str).doubleValue();
if(qu>act.getMoney()){
System.out.println("Insufficient balance, please re-enter");
}
else {
act.sub_Balance(qu);
System.out.println("The withdrawal is successful and your account balance is not yet"+act.getMoney());
Welcome();
SysOpter();
}
} while (true);
}
/*********quit******************/
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 is for reference only
The running results are as follows
Okay, friends, you can make your own ATM machine^_^