FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Collections-Framework-Example/BookApp.java at main · dyneth02/Java-Collections-Framework-Example · GitHub
dyneth02
/
Java-Collections-Framework-Example
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
10
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Collections-Framework-Example
/
BookApp.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
67 lines (56 loc) · 1.66 KB
Breadcrumbs
Java-Collections-Framework-Example
/
BookApp.java
Copy path
File metadata and controls
67 lines (56 loc) · 1.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL