-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibraryEntrance.java
More file actions
115 lines (100 loc) · 3.32 KB
/
LibraryEntrance.java
File metadata and controls
115 lines (100 loc) · 3.32 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
package librarymanager;
import java.util.Scanner;
public class LibraryEntrance {
private Scanner console = new Scanner(System.in);
String ISBN, title, author, genre, quantity;
int number, option;
// method, which launchs the app.
public void launch() {
display();
askOption();
}
// method, which asks for chosen option.
private void askOption() {
System.out.print("Choose: ");
if (console.hasNextInt()) {
option = console.nextInt();
console.nextLine();
doOption(option);
return;
}
}
// method, which initializes the option, based on the choice.
private void doOption(int what) {
System.out.println();
switch (what) {
case 1:
ISBN = askId();
title = askTitle();
author = askAuthor();
genre = askGenre();
quantity = askQuantity();
LibraryManager.addBook(ISBN, title, author, genre, quantity);
break;
case 2:
ISBN = askId();
LibraryManager.readData(ISBN);
break;
case 3:
ISBN = askId();
quantity = askQuantity();
LibraryManager.updateNum(ISBN, quantity);
break;
case 4:
ISBN = askId();
LibraryManager.removeBook(ISBN);
break;
case 5:
LibraryManager.showAll();
break;
case 6:
System.out.println("Program is terminated.");
break;
default:
System.out.println("We only have options from 1 to 6.");
break;
}
}
// method, which displays the menu.
private void display() {
System.out.println("===LIBRARY MANAGMENT");
System.out.println("1. Add book.");
System.out.println("2. Find book.");
System.out.println("3. Update book's quantity.");
System.out.println("4. Remove book.");
System.out.println("5. Show storage.");
System.out.println("6. Exit.");
}
// method, which asks for book's ID.
private String askId() {
System.out.print("Write id: ");
return console.nextLine();
}
// method, wich asks for book's name.
private String askTitle() {
System.out.print("Write the title: ");
return console.nextLine();
}
// method, which asks for book's author.
private String askAuthor() {
System.out.print("Write the author: ");
return console.nextLine();
}
// method, which asks for the genre.
private String askGenre() {
System.out.print("Write the genre: ");
genre = console.nextLine();
return genre.toUpperCase();
}
// method, which asks for the book quantity.
private String askQuantity() {
System.out.print("Write the quantity: ");
if (console.hasNextInt()) {
number = console.nextInt();
console.nextLine();
} else {
System.out.println("Invalid data type!");
}
return String.valueOf(number);
}
}