-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
315 lines (275 loc) · 12.5 KB
/
Main.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import java.lang.String;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String userChoice, author, title, isbn, bookObjectChoice;
String[] bookInput;
int index = 0;
int libraryCount = 0;
int bookStoreCount = 0;
Book [] books = new Book[100];
while (true)
{
System.out.printf("Would you like to create a book object?:(yes/no): ");
do
{
bookObjectChoice = in.nextLine().trim().toLowerCase();
if (bookObjectChoice.equals("yes") == false && bookObjectChoice.equals("no") == false)
System.out.println("Oops! That's not a valid entry. Please try again: ");
} while(bookObjectChoice.equals("yes") != true && bookObjectChoice.equals("no") != true);
if (bookObjectChoice.equals("yes"))
{
System.out.printf("Enter the author, title, and isbn of the book seperated by /: ");
userChoice = in.nextLine();
bookInput = userChoice.split("/");
author = bookInput[0];
title = bookInput[1];
isbn = bookInput[2];
System.out.printf("Got it!\n\n");
System.out.printf("Now, tell me if it's a bookstore book or a library book(Enter BB for bookstore book or LB for library book): ");
do
{
bookObjectChoice = in.nextLine().trim().toLowerCase();
if (bookObjectChoice.equals("bb") == false && bookObjectChoice.equals("lb") == false)
System.out.printf("Oops! That's not a valid entry. Please try again: ");
} while(bookObjectChoice.equals("bb") != true && bookObjectChoice.equals("lb") != true);
System.out.println("Got it!");
if (bookObjectChoice.equals("bb"))
{
BookstoreBook bookStore = new BookstoreBook(title, author, isbn);
double listPrice;
boolean onsale;
double saleRate;
double bookPrice;
System.out.print("Enter the list price of " + bookStore.getTitle().toUpperCase() + " by " + author.toUpperCase() + ": $");
listPrice = in.nextDouble();
in.nextLine();
bookStore.setPrice(listPrice);
System.out.printf("Is it on sale?(yes/no): ");
userChoice = in.nextLine();
if (userChoice.equals("yes"))
onsale = true;
else
onsale = false;
bookStore.setOnSale(onsale);
System.out.printf("Deduction percentage: ");
userChoice = in.nextLine();
userChoice = userChoice.replace('%', ' ');
saleRate = Double.parseDouble(userChoice);
bookStore.setSaleRate(saleRate);
System.out.printf("Got it!\n\n");
System.out.println("Here is your bookstore book information: ");
listPrice = bookStore.getPrice();
if (bookStore.getOnSale())
{
bookPrice = listPrice * (1 - (saleRate / 100));
bookStore.setPrice(listPrice);
bookStore.setSaleRate(bookPrice);
System.out.println(bookStore);
books[index] = bookStore;
bookStoreCount++;
index++;
}
else
{
System.out.println("[" + bookStore.getIsbn() + "-" + bookStore.getTitle().toUpperCase() + " by " + bookStore.getAuthor().toUpperCase() + "-$" + String.format("%.2f", bookStore.getPrice()));
books[index] = bookStore;
bookStoreCount++;
index++;
}
}
else if (bookObjectChoice.equals("lb"))
{
LibraryBook library = new LibraryBook(title, author, isbn);
String subjectLetter = "Z";
int flag = 0;
System.out.printf("What's the subject: ");
while (flag == 0)
{
userChoice = in.nextLine().trim().toLowerCase();
switch(userChoice) {
case "general":
subjectLetter = "A";
flag = 1;
break;
case "philosophy":
subjectLetter = "B";
flag = 1;
break;
case "religion":
subjectLetter = "C";
flag = 1;
break;
case "world history":
subjectLetter = "D";
flag = 1;
break;
case "history of the americas":
subjectLetter = "E";
flag = 1;
break;
case "geography":
subjectLetter = "F";
flag = 1;
break;
case "anthropology":
subjectLetter = "G";
flag = 1;
break;
case "social sciences":
subjectLetter = "H";
flag = 1;
break;
case "internet":
subjectLetter = "I";
flag = 1;
break;
case "political science":
subjectLetter = "J";
flag = 1;
break;
case "law":
subjectLetter = "K";
flag = 1;
break;
case "education":
subjectLetter = "L";
flag = 1;
break;
case "music":
subjectLetter = "L";
flag = 1;
break;
case "fine arts":
subjectLetter = "N";
flag = 1;
break;
case "language":
subjectLetter = "P";
flag = 1;
break;
case "science":
subjectLetter = "Q";
flag = 1;
break;
case "medicine":
subjectLetter = "R";
flag = 1;
break;
case "agriculture":
subjectLetter = "S";
flag = 1;
break;
case "technology":
subjectLetter = "T";
flag = 1;
break;
case "military":
subjectLetter = "U";
flag = 1;
break;
default:
System.out.printf("Oops that's not a valid entry. Please Try Again: ");
}
}
System.out.println("Got it!");
System.out.printf("\n\n");
int randomNum = (int) Math.floor(Math.random() * (15 - 1 + 1) + 1);
int length = isbn.length() - 1;
char letterIsbn = library.getIsbn().charAt(length);
library.setCallNumber(subjectLetter, Integer.toString(randomNum), library.getAuthor().substring(0, 3), Character.toString(letterIsbn));
System.out.println("Here is your library book information: ");
System.out.printf("\n");
System.out.println(library);
System.out.printf("\n\n");
books[index] = library;
libraryCount++;
index++;
}
}
else
{
System.out.println("Sure!");
System.out.printf("\n\n");
System.out.println("Here are all the books you entered..." + String.format("\n\n"));
System.out.printf("Library Books(%d)\n", libraryCount);
for (int i = 0; i < libraryCount; i++)
System.out.printf("\t%s\n", books[i]);
System.out.println("----");
System.out.printf("Bookstore Books(%d)\n", bookStoreCount);
for (int i = 0; i < bookStoreCount; i++)
System.out.printf("\t%s\n", books[i]);
System.out.println("----");
do
{
System.out.print("Would you like to search for a book?(yes/no): ");
bookObjectChoice = in.nextLine().trim().toLowerCase();
if (bookObjectChoice.equals("yes") == false && bookObjectChoice.equals("no") == false)
System.out.println("Oops! That's not a valid entry. Please try again.");
} while(bookObjectChoice.equals("yes") != true && bookObjectChoice.equals("no") != true);
if (bookObjectChoice.equals("yes"))
{
System.out.println("Search by isbn, author, or title? ");
userChoice = in.nextLine().toLowerCase().trim();
boolean found = false;
if (userChoice.equals("isbn"))
{
System.out.println("Enter the isbn of your book: ");
userChoice = in.nextLine().trim().toUpperCase();
System.out.println("Here are the books which were found: ");
for (int i = 0; i < index; i++)
{
if (books[i].getIsbn().equals(userChoice))
{
found = true;
System.out.println(books[i]);
}
}
}
else if (userChoice.equals("author"))
{
System.out.println("Enter the first three letters of the author: ");
userChoice = in.nextLine().trim().toUpperCase();
System.out.println("Here are the books which were found: ");
for (int i = 0; i < index; i++)
{
if (books[i].getAuthor().substring(0, 3).equals(userChoice))
{
found = true;
System.out.println(books[i]);
}
}
}
else
{
System.out.println("Enter the name of your book: ");
userChoice = in.nextLine().toUpperCase().trim();
System.out.println("Here are the books which were found: ");
for (int i = 0; i < index; i++)
{
if (books[i].getTitle().equals(userChoice))
{
found = true;
System.out.println(books[i]);
}
}
}
if (!found)
{
System.out.println("...");
System.out.println("No books were found which match your search.");
}
System.out.println(String.format("\n\n") + "Take Care!");
break;
}
else
{
System.out.println("Take Care!");
break;
}
}
}
in.close();
}
}