Through the Java language, the use of methods, the initial realization of ATM ATM basic functions.
Import Java.util.Scanner;
public class ATM2 {
public static void Main (string[] args) {
TODO auto-generated Method Stub
Loginsystem ();
}
Login System Method:
public static void Loginsystem () {
Scanner scan = new Scanner (system.in);
System.out.println ("*******************************");
SYSTEM.OUT.PRINTLN ("******** Welcome to Huaxia First Bank!*********");
System.out.println ("*******************************");
int i=0;
for (i = 0;i<3;i++) {
System.out.println ("Please enter your account number:");
String username = Scan.nextline ();
System.out.println ("Please enter your password:");
String password = scan.nextline ();
if (Username.equals ("J145") &&password.equals ("HRWSMV")) {
System.out.println ("Congratulations, landing success!") ");
OS ();
Break
}else{
if (i<2) {
System.out.println ("Account or password error, you also have" + (2-i) + "Opportunity Please re-enter:");
}
}
}
if (i==3) {
SYSTEM.OUT.PRINTLN ("You have entered the error three times and the card has been confiscated, please contact the staff.") ");
}
}
Operating system methods:
public static void OS () {
while (true) {
Scanner scan = new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("Please choose your operation: 1, check the balance, 2, withdraw money, 3, save, 4, change the password; 5, exit.") ");
int choice = Scan.nextint ();
Switch (choice) {
Case 1:
System.out.println ("Your account balance: 1000000.00 yuan");
Break
Case 2:
Takemoney ();
Break
Case 3:
Savemoney ();
Break
Case 4:
ChangePassword ();
Break
Case 5:
System.out.println ("Thanks for using, goodbye!");
Return
Default:
System.out.print ("Your input is not correct, please re-enter:");
}
}
}
How to withdraw money:
public static void Takemoney () {
while (true) {
Scanner scan = new Scanner (system.in);
System.out.println ("Please enter your withdrawal amount:");
int Takemoney = Scan.nextint ();
if (takemoney% 100 ==0) {
System.out.println ("Please take your money if you are successful.") ");
System.out.println ("Your balance is" + (1000000.00-takemoney) + "Yuan");
Break
}else {
SYSTEM.OUT.PRINTLN ("Your input is not correct, please re-enter!");
}
}
}
How to save money:
public static void Savemoney () {
Scanner scan = new Scanner (system.in);
while (true) {
System.out.println ("Please put your deposit note (must be for the whole hundred banknotes, please do not fold)");
int Savemoney = Scan.nextint ();
if (savemoney% 100 ==0) {
System.out.println ("Congratulations on your saving success, please continue with your operation.") ");
Break
}else {
System.out.println ("You put the bill is not correct, please re-put!");
}
}
}
The preliminary implementation of the Java---ATM teller machine