-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATMMachine.java
214 lines (168 loc) · 6.19 KB
/
ATMMachine.java
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import jdk.swing.interop.SwingInterOpUtils;
import java.util.Scanner;
public class ATMMachine {
//global variable for initial amount
static final double init_balance = 1000;
//global variable for current amount/amount update
static double current_amount;
//global variable for account number
static int acct_no;
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// accessing the menu
TopMenu();
//select an input for the menu
System.out.println("Please select an option: ");
int menu_input = input.nextInt();
if (menu_input == 5)
System.out.println();
else {
while (menu_input != 1) {
System.out.println("Please Sign in first!!!");
System.out.println("Select 1 to sign in.");
menu_input = input.nextInt();
}
}
switch (menu_input){
case 1:
//SignIn
System.out.println("Enter your account number: ");
// Scanner input1 = new Scanner(System.in);
acct_no = input.nextInt();
//assume account numbers are from (0...9)
//validate input
int counter = 1;
while(acct_no<0 || acct_no>9){
System.out.println("Number is not valid!!!");
System.out.println();
/**
* menu is displayed again @TopMenu when acount number is invalid
*/
TopMenu();
System.out.println("Please select an option: ");
menu_input = input.nextInt();
System.out.println("Enter your account number: ");
acct_no = input.nextInt();
counter++;
}
//ACCESS MENU AFTER SIGNING IN
TopMenu_2();
break;
case 5:
//EXIT OPTION
System.out.println("GoodBye.");
break;
default:
if (menu_input<1 || menu_input>5)
System.out.println("Number out of range!");
break;
}
}
//This displays The Menu
public static void TopMenu(){
System.out.println("Welcome to the ATM Machine.");
System.out.println("1.Sign In");
System.out.println("2.Balance");
System.out.println("3.Deposit");
System.out.println("4.Withdraw");
System.out.println("5.Exit");
}
//This Displays Menu After Signed In
public static void TopMenu_2(){
System.out.println("Please select an option: ");
System.out.println("1.Balance");
System.out.println("2.Deposit");
System.out.println("3.Withdraw");
System.out.println("4.Exit");
// Scanner input = new Scanner(System.in);
int menu_input = input.nextInt();
switch (menu_input){
case 1:
//Balance check
Bal();
break;
case 2:
//Deposit
Deposit_();
break;
case 3:
//Withdrawal
Withdrawl_();
break;
case 4:
exit_();
break;
default:
System.out.println("Invalid Entry.");
System.out.print("Please try again.");
break;
}
}
//Using an Aray to Hold Account Balance
/* public static void AcBal(){
int size = 10;
//double init_balance = 1000;
double acctbal[] = new double[size];
for(int i = 0 ; i<size; i++){
acctbal[i] = init_balance;
System.out.println(init_balance);
}
}*/
/**Balance option @Bal**/
public static void Bal(){
int size = 10;
// double init_balance = 1000;
double acctbal[] = new double[size];
for(int i = 0 ; i<size; i++){
acctbal[i] = init_balance;
acctbal[acct_no] = init_balance;
// System.out.println(init_balance);
}
System.out.println("Available Balance:$" + init_balance);
System.out.println("Updated Balance: " + current_amount);
//Balance checking
if (init_balance<100)
System.out.println("Low Balance.");
System.out.println();
}
/**Deposit option @Deposit_**/
public static void Deposit_(){
//prompt user to enter amount
System.out.print("Please enter an amount: ");
//Scanner input = new Scanner(System.in);
int amount = input.nextInt();
//verify if input is positive
while(amount<1){
System.out.println("Invalid amount.\nTry again.");
System.out.print("Please enter an amount: ");
amount = input.nextInt();
TopMenu_2();
}
//update of current balance
current_amount = amount + init_balance;
System.out.println("Your current balance: $" + current_amount);
}
/**Withdrawal option @Withdrawl_**/
public static void Withdrawl_(){
//prompt user to enter amount to withdrawl
// System.out.print("Enter an amount: ");
//int amount = input.nextInt();
if (init_balance>0)
System.out.println("Your balance is sufficient.");
else
System.out.println("Your balance is insuffiencient.");
Bal();
System.out.println("Enter an amount: ");
// Scanner input = new Scanner(System.in);
int amount = input.nextInt();
//calculates and displays current balance after withdrawal
current_amount = init_balance - amount;
System.out.println("Your available balance is: $" + current_amount);
}
/**exit option for user **/
public static void exit_(){
System.out.println("GoodBye.");
System.out.println();
TopMenu();
}
}