-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibraryApplication.java
131 lines (77 loc) · 2.45 KB
/
LibraryApplication.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
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class LibraryApplication{
private static Book[] Bookarray=new Book[5];
static Scanner input=new Scanner(System.in);
public static void main(String[]args) {
int option;
fillLibrary();
option=showMenu();
if (option==1) {
showLibrary();
}
else if (option==2) {
showBook();
}
else if (option==3) {
showLibraryByTitle();
}
else if (option==4) {
showLibraryByCost();
}
else if (option==5) {
clearConsole();
}
}
public static void fillLibrary() {
Bookarray[0]=new Book("Crow Winter","Karen McBride",336,2019,9780221076756L,22.99);
Bookarray[1]=new Book("All the Quiet Places","Brian Thomas Isaac",288,2021,9781990071027L,22.00);
Bookarray[2]=new Book("The Break","Katherena Vermette",360,2016,9781525264641L,23.99);
Bookarray[3]=new Book("Fire Keepers Daughter","Angeline Boulley",496,2021,9781250866035L,24.20);
Bookarray[4]=new Book("There There","Tommy Orange",304,2018,9780525436140L,21.00);
}
public static int showMenu() {
int option2;
System.out.println("1 show the library");
System.out.println("2 Show book");
System.out.println("3 Show library by Title");
System.out.println("4 Show library by Cost");
System.out.println("5 Exit");
System.out.println("Which option do u choose");
option2=input.nextInt();
return option2;
}
public static void showLibrary() {
for (int counter=0; counter<Bookarray.length; counter++) {
System.out.println(Bookarray[counter]);
}
}
public static void showBook() {
String word;
System.out.println("Enter a book keyword lmao bruh");
word=input.next();
for (int u=0; u<Bookarray.length; u++) {
if (Bookarray[u].getTitle().contains(word)) {
System.out.println(Bookarray[u]);
}
}
}
public static void showLibraryByTitle() {
Arrays.sort(Bookarray,Comparator.comparing(Book::getTitle));
for (int counter=0; counter<Bookarray.length; counter++) {
System.out.println(Bookarray[counter]);
}
}
public static void showLibraryByCost() {
Arrays.sort(Bookarray,Comparator.comparing(Book::getCost));
for (int counter=0; counter<Bookarray.length; counter++) {
System.out.println(Bookarray[counter]);
}
}
private static void clearConsole() {
//
for(int row = 1; row <= 50; row++)
System.out.println();
}
}