Import Java.util.Scanner;
public class atm{
static int allmoney=150000; ATM Existing balances
static int all=200000; The largest number of ATMs
static int money = 10000; Initialize the user's balance
public static void Main (string[] args) {
System.out.print ("*********************************");
System.out.println ();
System.out.print ("********* Welcome to use chicken version ATM **********");
System.out.println ();
System.out.print ("****1. Login ***************2. Exit * * * *");
System.out.println ();
Scanner s=new Scanner (system.in);
int i = S.nextint ();
if (i==1) {//select 1 to enter the ATM machine to construct the login function
Denglu ();
Gongneng ();
}
else{
System.out.println ("******* has exited system *******");
System.exit (0); Exit the program directly
}
}
public static void Denglu () {
for (int x =1;x<4;x++) {
int j=3-x;
Scanner t = new Scanner (system.in);
System.out.println ("Please enter user name:");
int Yonghuming=t.nextint ();
System.out.println ("Please enter password");
int Mima=t.nextint ();
if (yonghuming==123&&mima==321) {
System.out.println ("Landing success");
Break
}
else{
SYSTEM.OUT.PRINTLN ("Please re-enter, you still have" +j+ "opportunity");
if (j==0) {
System.out.println ("******* has exited system *******");
System.exit (0); Exit the program directly
Continue
}
}
}return;
}
public static void Gongneng () {
Scanner t=new Scanner (system.in);
System.out.println ("Please enter the function you want to select: 1. Check the balance 2. Withdrawals 3. Deposit 4. Exit");
int Gongneng =t.nextint ();
Switch (Gongneng) {//Construct the function menu
Case 1:SYSTEM.OUT.PRINTLN ("Your current account balance is" +money);
Case 2:SYSTEM.OUT.PRINTLN ("Please enter the amount to be removed");
for (int i=0;; i++) {
int Quqian = T.nextint ();
if (quqian==0&&quqian<0) {
SYSTEM.OUT.PRINTLN ("Input error, please re-enter");
Continue
}
else if (Quqian>money) {
System.out.println ("Your balance is insufficient, please re-enter");
Continue
}
else if (quqian%100!=0) {
SYSTEM.OUT.PRINTLN ("must be a multiple of 100, re-enter");
Continue
}
else{
SYSTEM.OUT.PRINTLN ("Please collect the money");
Money-=quqian;
System.out.println ("Your account is still left" +money);
Break
}
}
Break
Case 3:
for (int i = 0;;; i++) {
System.out.print ("Please enter the amount to be saved");
Scanner q=new Scanner (system.in);
int cun = Q.nextint ();
if (cun%100!=0) {
SYSTEM.OUT.PRINTLN ("Deposit must be a multiple of 100, please re-enter");
Continue
}
else if (Cun+allmoney>all) {
SYSTEM.OUT.PRINTLN ("The ATM doesn't fit, please re-enter");
Continue
}
else if (cun<0&&cun==0) {
SYSTEM.OUT.PRINTLN ("The amount is incorrect, please re-enter");
Continue
}
else{
System.out.println ("Save your Money successfully, your balance is" + (Cun+money));
}
}
Case 4:system.out.println ("******* has exited system *******");
System.exit (0);
}
Return
}
}
1 Talk about the use of knowledge points, from the top to down, the first use is input, how to input variables, the use of scanner, the next is to use the for nested if statement, for loop to control the number of times you enter, when you enter the user name password error to 3 times, give a hint and launch the program, When you lose the username password, you go to the next block of code,
2 here to use the module, call module is a focus, because later write code you can not write to the main method inside, so readability is poor, here my second Gongneng module write a bit cumbersome.
3 Gongneng module is used in the switch inside the nested if loop, because before the class has defined three global variables, so these three quantities in any module here can be used directly; here it should be realized you withdraw money, save and then go to check the balance, the balance will have corresponding changes , but if you check the balance first, you will find that the balance cannot correspond to the balance you have defined above. It seems that today is not possible, the back of time to complete this small function.
Vegetable Chicken Program Ape Start: A simple ATM machine for Java basics