-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATMCLASS.java
More file actions
132 lines (126 loc) · 3.93 KB
/
ATMCLASS.java
File metadata and controls
132 lines (126 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package ATMJerryJia;
import java.util.Scanner;
public class ATMCLASS {
static String accountNum = "Justin"; // the account number
static int accountPin = 1234; // the valid pin
static Scanner userInputAccount = new Scanner(System.in);
static Scanner userInputPin = new Scanner(System.in);
static int balance = 10000; // the global var for default balance
static Scanner userInputChoise = new Scanner(System.in);
static Scanner userInputDeposit = new Scanner(System.in);
static Scanner userInputBalance = new Scanner(System.in);
static Scanner userInputWithdraw = new Scanner(System.in);
static int choiseInput = 0;
static int restartProgramCheck = 0;
static String userChoice = "no" ;
static Scanner userInputWhetherAgain = new Scanner(System.in);
/* All the other are the Scanner looking for user's input*/
public static void main(String [] args){ // the main class
String accountInput = "";
int pinInput = 0;
int countAccount = 0;
int countPin = 0;
while(countAccount ==0) {
System.out.println("Welcome to Jia's ATM \n Please enter your username: ");
accountInput = userInputAccount.nextLine();
countAccount = CheckAccount(accountInput);
}
System.out.println("Thanks!");
while(countPin ==0) {
System.out.println("Please enter your pin sir :" );
pinInput = userInputPin.nextInt();
countPin = CheckPin(pinInput);
}
System.out.println("Welcome! Justin. ");
do {
enterStartAgain();
System.out.println("Is there anything else you want to do ? \n Enter 'yes' or 'no' please :");
userChoice = userInputWhetherAgain.nextLine();
if(userChoice.equals("yes")){
continue;
}
else if (userChoice.equals("no")) {
System.out.println("Thank you for using Jia's ATM. I will see you next time! ");
break;
}
else {
System.out.println("Sorry, I cannot understand you. See you next time !" );
break;
}
}while(restartProgramCheck == 0);
}
public static void enterStartAgain() { // a class which can call withdraw, deposit, and check balance
System.out.println("What do you want to do Mr. Kutscherousky? Press 1 to withdraw, 2 to deposit, and 3 to check your balance :");
choiseInput = userInputChoise.nextInt();
while(restartProgramCheck == 0) {
if(choiseInput == 1) {
restartProgram(1);
choiseInput =+3;
break;
}
else if (choiseInput ==2) {
restartProgram(2);
break;
}
else if(choiseInput ==3) {
restartProgram(3);
break;
}
break;
}
}
public static void restartProgram(int Num) { // the withdraw class
choiseInput = Num;
while(Num ==1) {
int withdrawCheck = 0 ;
int withdrawInput = 0;
while (withdrawCheck ==0){
choiseInput =+3;
System.out.println("How much do you wish to withdraw : ");
withdrawInput = userInputWithdraw.nextInt();
if (withdrawInput <= balance) {
withdrawCheck ++;
balance -= withdrawInput;
System.out.println("Congrats! Now the amount of money in your account is : " + balance);
break;
}
else if(withdrawInput > balance) {
System.out.println("Sorry, you cannot withdraw more than you have. ");
}
}
break;
}// The loop when Num = 1
while(Num ==2) { // the deposit class
int depositCheck =0;
int depositInput = 0;
while(depositCheck == 0) {
System.out.println("How much do you wish to deposit : ");
depositInput = userInputDeposit.nextInt();
balance += depositInput;
System.out.println("Congrats! Now the amount of Money in your account is :" + balance);
depositCheck++;
}
break;
}// The loop when Num = 2
while(Num ==3) { // check balance class
System.out.println("Your balance in your account is :" + balance);
break;
}
}
public static int CheckAccount(String Account) { // check account
if(Account.equals(accountNum)) {
return -1;
}
else {
return 0;
}
}
public static int CheckPin(int Pin) { //check pin
if(Pin == accountPin) {
return -1;
}
else {
return 0;
}
}
}