-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperator.java
More file actions
230 lines (178 loc) · 7.87 KB
/
Copy pathOperator.java
File metadata and controls
230 lines (178 loc) · 7.87 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/**
*
* @author Rylan, Zach, Brandon
*/
public class Operator extends User{
public Operator(){
super();
}
public void removeDocument(){
System.out.println("Type the ISBN of the document you would like to remove.");
int inputInt = Integer.parseInt(stdin.nextLine());
if(instance.database.removeDocument(inputInt) == -1){
System.out.println("File could not be removed because it does not exist");
}
else if(instance.database.removeDocument(inputInt) == -1){
System.out.println("Document removed.");
}
}
public void addDocument(){
System.out.println("What kind of document would you like to add\n");
System.out.println("Type 'J' for Journal, 'B' for Book, or 'M' for Magazine\n");
boolean goodInput = false;
while(!goodInput){
String input = stdin.nextLine();
if(input.compareTo("J") == 0){
System.out.println("Lets make a Journal");
addJournal();
goodInput = true;
}
else if(input.compareTo("B") == 0){
System.out.println("Lets make a Book");
addBook();
goodInput = true;
}
else if(input.compareTo("M") == 0){
System.out.println("Lets make a Magazine");
addMagazine();
goodInput = true;
}
else {
System.out.println("Sorry, could not read that. Please try again.");
}
}
}
public void addJournal(){
System.out.println("What is the title of your Journal?\n");
String title = stdin.nextLine();
System.out.println("What is the author of your Journal?\n");
String author = stdin.nextLine();
System.out.println("What is the price of your journal?\n");
double price = Double.parseDouble(stdin.nextLine());
System.out.println("What is the ISBN of your Journal?\n");
int isbn = Integer.parseInt(stdin.nextLine());
System.out.println("What is the filepath of your Journal?\n");
String filepath = stdin.nextLine();
System.out.println("What is the stock of your Journal?\n");
int stock = Integer.parseInt(stdin.nextLine());
Journal journal = new Journal(title, author, price, isbn, filepath, stock);
System.out.println("Made a journal, lets see if I did tho");
instance.database.addDocument(journal);
System.out.println("Document added");
journal.executeStrategy();
}
public void addBook(){
System.out.println("What is the title of your Book?\n");
String title = stdin.nextLine();
System.out.println("What is the author of your Book?\n");
String author = stdin.nextLine();
System.out.println("What is the price of your Book?\n");
double price = Double.parseDouble(stdin.nextLine());
System.out.println("What is the ISBN of your Book?\n");
int isbn = Integer.parseInt(stdin.nextLine());
System.out.println("What is the filepath of your Book?\n");
String filepath = stdin.nextLine();
System.out.println("What is the stock of your Book?\n");
int stock = Integer.parseInt(stdin.nextLine());
Book book = new Book(title, author, price, isbn, filepath, stock);
System.out.println("Made a book, lets see if I did tho");
instance.database.addDocument(book);
book.executeStrategy();
}
public void addMagazine(){
System.out.println("What is the title of your Magazine?\n");
String title = stdin.nextLine();
System.out.println("What is the author of your Magazine?\n");
String author = stdin.nextLine();
System.out.println("What is the price of your Magazine?\n");
double price = Double.parseDouble(stdin.nextLine());
System.out.println("What is the ISBN of your Magazine?\n");
int isbn = Integer.parseInt(stdin.nextLine());
System.out.println("What is the filepath of your Magazine?\n");
String filepath = stdin.nextLine();
System.out.println("What is the stock of your Magazine?\n");
int stock = Integer.parseInt(stdin.nextLine());
Magazine magazine = new Magazine(title, author, price, isbn, filepath, stock);
System.out.println("Made a magazine, lets see if I did tho");
instance.database.addDocument(magazine);
magazine.executeStrategy();
}
public void updateDocument(int targetISBN){
System.out.println("Updating document " + targetISBN + ".");
Document d = instance.database.searchForDocument(targetISBN);
String input = stdin.nextLine();
if(d == null){
System.out.println("Sorry, no document with that ISBN exists.");
return;
}
System.out.println("Would you like to change the title? Y/N");
input = stdin.nextLine();
if(input.matches("Y")){
System.out.println("What would you like to change the title to?");
input = stdin.nextLine();
d.setTitle(input);
}
System.out.println("Would you like to change the Author's name? Y/N");
input = stdin.nextLine();
if(input.matches("Y")){
System.out.println("What would you like to change their name to? Y/N");
input = stdin.nextLine();
d.setAuthorName(input);
}
System.out.println("Would you like to change the path to the document?, Y/N");
input = stdin.nextLine();
if(input.matches("Y")){
System.out.println("What would you like to change the path to?, Y/N");
input = stdin.nextLine();
d.setPath(input);
}
System.out.println("Would you like to change the current stock of the Document?");
input = stdin.nextLine();
if(input.matches("Y")){
System.out.println("What is the new stock of the document?");
int inputInt = stdin.nextInt();
d.setStockCount(inputInt);
}
instance.getDatabase().removeDocument(targetISBN);
instance.getDatabase().addDocument(d);
System.out.println("Document has been updated. Displaying new values of document");
d.display();
}
@Override
public void showOptions() {
while(true){
stdin.reset();
System.out.println("Press 1 to add document.");
System.out.println("Press 2 to remove document.");
System.out.println("Press 3 to update document.");
System.out.println("Enter 'Q' to quit");
String input = stdin.nextLine();
if(input.matches("Q")){
break;
}
while(true){
if(input.matches("1")){
addDocument();
System.out.println("\n");
break;
}
else if(input.matches("2")){
removeDocument();
System.out.println("\n");
break;
}
else if(input.matches("3")){
System.out.println("Please type the ISBN of the document that you would like to update.");
int inputInt = stdin.nextInt();
updateDocument(inputInt);
System.out.println("\n");
break;
}
else{
System.out.println("invalid input.");
break;
}
}
}
}
}