forked from txs72/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATM.java
More file actions
executable file
·95 lines (93 loc) · 2.8 KB
/
ATM.java
File metadata and controls
executable file
·95 lines (93 loc) · 2.8 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
/* */ package ch10;
/* */
/* */ import java.util.Scanner;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ class ATM
/* */ {
/* */ private Account[] accounts;
/* 18 */ int state = 0;
/* */
/* */
/* */
/* 22 */ int selectedID = 0;
/* 23 */ int operationID = 0;
/* */
/* */ ATM() {
/* 26 */ this.accounts = new Account[10];
/* 27 */ for (int i = 0; i < this.accounts.length; i++) {
/* 28 */ this.accounts[i] = new Account(i, 100.0D);
/* */ }
/* 30 */ this.scanner = new Scanner(System.in);
/* */ }
/* */ Scanner scanner;
/* */ public void displayMessage() {
/* */ while (true) {
/* 35 */ switch (this.state) {
/* */ case 0:
/* 37 */ displayMainMenu();
/* */
/* */ case 1:
/* 40 */ displayOperaitonSelection();
/* */
/* */ case 2:
/* 43 */ doOperation();
/* */ }
/* */ }
/* */ }
/* */
/* */
/* */ public void displayMainMenu() {
/* 50 */ System.out.print("Enter an id: ");
/* 51 */ this.selectedID = this.scanner.nextInt();
/* 52 */ this.state = 1;
/* */ }
/* */
/* */ public void displayOperaitonSelection() {
/* 56 */ System.out.println("Main menu");
/* 57 */ System.out.println("1. check balance");
/* 58 */ System.out.println("2. withdraw");
/* 59 */ System.out.println("3. deposit");
/* 60 */ System.out.println("4. exit");
/* 61 */ System.out.print("Enter a choice: ");
/* 62 */ this.operationID = this.scanner.nextInt();
/* 63 */ if (this.operationID == 1) {
/* 64 */ System.out.println("The balance is " + this.accounts[this.selectedID].getBalance());
/* */ }
/* 66 */ else if (this.operationID == 2 || this.operationID == 3) {
/* 67 */ this.state = 2;
/* */ }
/* 69 */ else if (this.operationID == 4) {
/* 70 */ this.state = 0;
/* */ }
/* */ }
/* */
/* */ public void doOperation() {
/* 75 */ double amount = 0.0D;
/* 76 */ if (this.operationID == 2) {
/* 77 */ System.out.print("Enter an amount to withdraw: ");
/* 78 */ amount = this.scanner.nextDouble();
/* 79 */ this.accounts[this.selectedID].withDraw(amount);
/* 80 */ this.state = 1;
/* */ }
/* 82 */ if (this.operationID == 3) {
/* 83 */ System.out.print("Enter an amount to deposit: ");
/* 84 */ amount = this.scanner.nextDouble();
/* 85 */ this.accounts[this.selectedID].deposit(amount);
/* 86 */ this.state = 1;
/* */ }
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch10/ATM.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/