-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice.java
More file actions
165 lines (113 loc) · 2.83 KB
/
Practice.java
File metadata and controls
165 lines (113 loc) · 2.83 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
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
import java.util.*;
//Main
public class Practice {
public static void main(String[] args) {
new User();
}
}
//
interface actions{
void getUser();
boolean getInfo(int choice);
void getDisplay();
void setDeposit();
void getWithdraw();
void setData();
}
abstract class Output implements actions{
static Scanner console = new Scanner(System.in);
private int choice = -1;
private String username = "";
private boolean indicator = false;
private double balance = 100;
@Override
public void setData() {
}
Output(){
System.out.println("Welcome to ATM");
getUser();
}
public void getUser() {
System.out.println("[1] Log in | [2] Create User | [3] Exit");
while(true) {
while(true) {
System.out.print("Enter: ");
choice = console.nextInt();
if(choice == 3)
break;
if(choice == 1 || choice == 2)
break;
}
if(choice == 3) {
System.out.println("Thank you for using our system!");
break;
}
if(getInfo(choice) == true)
break;
}
//Withdrawal or Deposit
while (true) {
System.out.println("[1] Display Balance | [2] Deposit | [3] Withdraw | [4] Exit" + "\nEnter: ");
int n = console.nextInt();
if(n == 1)
getDisplay();
if(n == 2)
setDeposit();
if(n == 3)
getWithdraw();
if(n == 4) {
System.out.println("Thank you for using our system!");
break;
}
}
}
public boolean getInfo(int choice) {
if(choice == 1) {
while(!indicator) {
System.out.print("Enter username: ");
String getInfo = console.next();
if(!getInfo.equals(username)) {
System.out.println("User not found");
System.out.println("Do you want to enter again? [yes] | [no]");
char get = console.next().charAt(0);
if(get == 'N' || get == 'n' )
break;
}
else {
indicator = true;
}
}
}
else {
System.out.println("Create Username: ");
setUser(console.next());
System.out.println("Username created");
}
return indicator;
}
void setUser(String user) {
this.username = user;
}
public void getDisplay() {
System.out.println("Your balance is: " + this.balance);
}
public void setDeposit() {
System.out.println("Enter amount to deposit: ");
balance += console.nextDouble();
System.out.println("Sucessful Deposit");
}
public void getWithdraw() {
System.out.println("Enter amount to withdraw: ");
double check = console.nextDouble();
if(check > this.balance)
System.out.println("Withdraw amount exceed from the current balance");
else {
this.balance -= check;
System.out.println("Sucessful Withdraw");
}
}
}
class User extends Output{
User(){
}
}