-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSafetyDepositBox.java
More file actions
135 lines (109 loc) · 4.95 KB
/
Copy pathSafetyDepositBox.java
File metadata and controls
135 lines (109 loc) · 4.95 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
import java.util.Scanner;
import java.io.IOException;
import java.util.ArrayList;
public class SafetyDepositBox {
public ArrayList<String> Valuables;
private static Scanner input = new Scanner(System.in);
private static int limit = 10;
private static String exitCharacter = "XXXXX";
private static String stopCharacter = "YYYYY";
private void ExitPrint() {
System.out.printf("INPUT '%s' (without quotes) AT ANY POINT TO RETYPE\n", exitCharacter);
}
private void StopPrint() {
System.out.printf("INPUT '%s' (without quotes) AT ANY POINT TO STOP\n\n", stopCharacter);
}
public SafetyDepositBox() {
this.Valuables = new ArrayList<String>();
ExitPrint();
StopPrint();
for (int i = 0; i < 10; i++) {
System.out.printf("Enter valuable to deposit #%d: \n", i + 1);
String Valuable = "";
Valuable += input.nextLine();
if (Valuable.contains(exitCharacter))
{
i -= 1;
System.out.println("Please retype.");
continue;
} else if (Valuable.contains(stopCharacter)) {
i -= 1;
System.out.printf("Are you sure you'd like to stop inserting items in the deposit box? Enter %s again to confirm, and anything else to cancel.\n", stopCharacter);
if (input.nextLine().equals(stopCharacter)) {
return;
} else {
System.out.println("Alright.");
continue;
}
}
this.Valuables.add(Valuable);
try {
BankMain.menu();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private static boolean CheckCharacter(String chr) {
return input.nextLine().equals(chr);
}
public void DepositValuables() {
if (this.Valuables.size() >= limit) {
System.out.println("Your box is full! Remove some items from the deposit box?");
RemoveValuables();
}
System.out.printf("TYPE %s AT ANY POINT TO STOP PUTTING ITEMS IN THE BOX\n", exitCharacter);
String response = "1";
for (int i = this.Valuables.size(); i < limit; i++) {
System.out.printf("What would you like to add to slot %d of the deposit box?\n", i + 1);
String valuable = input.nextLine();
if (valuable.equals(exitCharacter)) {
System.out.println("Are you sure you want to stop putting items in the box? Enter XXXXX again to confirm");
if (SafetyDepositBox.CheckCharacter(exitCharacter)) {
break;
}
System.out.println("Alright.");
i--;
continue;
}
System.out.printf("Are you sure you want to add %s to your deposit box at slot %d?\n", valuable, i + 1);
System.out.println("Press 1 to confirm, and anything else to cancel.");
response = input.nextLine();
if (response.equals(exitCharacter)) {
System.out.println("Are you sure you want to stop putting items in the box? Enter XXXXX again to confirm");
if (SafetyDepositBox.CheckCharacter(exitCharacter)) {
break;
}
System.out.println("Alright.");
i--;
continue;
} else {
Valuables.add(valuable);
}
}
}
public void DisplayContentsOfBox() {
System.out.println("Here are your Valuables.");
for (int i = 0; i < Valuables.size(); i++){
System.out.printf("%d. %s\n", i + 1, Valuables.get(i));
}
}
public void RemoveValuables() {
StopPrint();
System.out.println("Enter the index of the item you want to remove.");
String index = input.nextLine();
if (index.contains(stopCharacter)) {
System.out.printf("Are you sure you want to stop removing valuables? Retype %s to confirm.\n", stopCharacter);
if (input.nextLine().equals(stopCharacter)) {
return;
}
} else {
System.out.printf("Are you sure you want to remove %s from your deposit box? Type 1 to confirm.\n", Valuables.get(Integer.parseInt(index) - 1));
if (input.nextLine().equals("1")) {
Valuables.remove(Integer.parseInt(index) - 1);
System.out.println("Removed.");
}
}
}
}