-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookApp.java
More file actions
67 lines (56 loc) · 1.66 KB
/
BookApp.java
File metadata and controls
67 lines (56 loc) · 1.66 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
package version_e.q2;
import java.util.PriorityQueue;
import java.util.Scanner;
public class BookApp {
public static PriorityQueue<String> books = new PriorityQueue<>();
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
String bookName;
String needToRemove;
do {
System.out.print("Enter the Book Name : ");
bookName = read.nextLine();
if (!bookName.equalsIgnoreCase("done")) {
addBook(bookName);
}
} while (!"done".equalsIgnoreCase(bookName));
System.out.print("Do you want to remove a book ? : ");
needToRemove = read.next();
if (needToRemove.equalsIgnoreCase("Yes")) {
System.out.print("Enter the book's name that you want to remove : ");
read.nextLine();
removeBook(read.nextLine());
}
else if (needToRemove.equalsIgnoreCase("No")) {
System.out.println("Okey");
}
else {
System.out.println("Wrong input");
}
displayBooks();
}
public static void addBook(String bookName) {
books.offer(bookName);
}
public static void removeBook(String bookName) {
if (books.contains(bookName)) {
books.remove(bookName);
System.out.println();
System.out.println("The book is removed successfully..!");
System.out.println();
}
else {
System.out.println();
System.out.println("The book is not in the this list..!");
System.out.println();
}
}
public static void displayBooks() {
System.out.println();
System.out.println("The total number of books in the list : " + books.size());
for (String displayedBook : books) {
System.out.println(displayedBook);
}
}
}