-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibraryDatabase.java
More file actions
40 lines (39 loc) · 1.62 KB
/
LibraryDatabase.java
File metadata and controls
40 lines (39 loc) · 1.62 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
import java.util.InputMismatchException;
import java.util.Scanner;
public class LibraryDatabase {
public static void main(String[] args) {
BookHashManager.fillMap();
Scanner stdIn = new Scanner(System.in);
boolean validInput = false;
int input = 1;
System.out.println("Welcome to the library database.");
while (input != 3) {
System.out.println("What would you like to do?\n" +
"1). Search for a specific book by title.\n" +
"2). Search library for any of the following properties: Title, Author, Genre, Year Published, Page Count, Price\n" +
"3). Quit the program.");
do {
try {
input = stdIn.nextInt();
validInput = (input > 0 && input < 4);
} catch (InputMismatchException e) {
validInput = false;
}
if (!validInput) {
System.out.println("Invalid Input. Please try again with a number 1-3");
}
stdIn.nextLine();
} while (validInput == false);
switch(input){
case 1:
System.out.println("Enter a book's name.");
BookHashManager.searchByName(stdIn.nextLine());
break;
case 2:
System.out.println("Enter a number or word(s) you'd like to search for in all the above properities.");
BookHashManager.searchByProperty(stdIn.nextLine());
}
}
stdIn.close();
}
}