Skip to content

Commit acb6d12

Browse files
author
hajajmaor@gmail.com
committed
complete?
1 parent 2111ade commit acb6d12

File tree

3 files changed

+63
-19
lines changed

3 files changed

+63
-19
lines changed

bin/app/App.class

863 Bytes
Binary file not shown.

src/app/App.java

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ private static Member createNewMember() {
121121

122122
static Member getMember() throws InterruptedException {
123123

124-
System.out.println("\nmembers:");
125-
for (Member member : members)
126-
System.out.println(member);
124+
showMembers();
127125
System.out.print("enter ID to search: ");
128126
int id = scan.nextInt();
129127
boolean found = false;
@@ -151,9 +149,7 @@ static Member getMember() throws InterruptedException {
151149

152150
static Book getBook() throws InterruptedException {
153151

154-
System.out.println("\nBooks:");
155-
for (Book book : books)
156-
System.out.println(book);
152+
showBooks();
157153
System.out.print("enter ID to search: ");
158154
int id = scan.nextInt();
159155
boolean found = false;
@@ -177,9 +173,7 @@ static Book getBook() throws InterruptedException {
177173

178174
static Supplier getSupplier() throws InterruptedException {
179175

180-
System.out.println("\nSuppliers:");
181-
for (Supplier supplier : suppliers)
182-
System.out.println(supplier);
176+
showSuppliers();
183177
System.out.print("enter ID to search: ");
184178
int id = scan.nextInt();
185179
boolean found = false;
@@ -200,4 +194,53 @@ static Supplier getSupplier() throws InterruptedException {
200194
}
201195
return null;
202196
}
197+
198+
static GregorianCalendar newDate() {
199+
System.out.print("enter year:");
200+
int year = scan.nextInt();
201+
System.out.print("enter month:");
202+
int month = scan.nextInt();
203+
System.out.print("enter day:");
204+
int day = scan.nextInt();
205+
GregorianCalendar date = new GregorianCalendar(year, month, day);
206+
return date;
207+
}
208+
209+
static Purchase purchaseBook() {
210+
try {
211+
// public Purchase(int id, int amount, Book book, GregorianCalendar date)
212+
System.out.print("Enter ID of purchase:");
213+
int id = scan.nextInt();
214+
Book book = getBook();
215+
System.out.print("Enter amount of book in purchase:");
216+
int amount = scan.nextInt();
217+
GregorianCalendar date = newDate();
218+
Purchase p1 = new Purchase(id, amount, book, date);
219+
purchases.add(p1);
220+
return p1;
221+
222+
} catch (Exception e) {
223+
System.out.println(e);
224+
}
225+
226+
return null;
227+
}
228+
229+
static void showMembers() {
230+
System.out.println("\nmembers:");
231+
for (Member member : members)
232+
System.out.println(member);
233+
}
234+
235+
static void showBooks() {
236+
System.out.println("\nBooks:");
237+
for (Book book : books)
238+
System.out.println(book);
239+
}
240+
241+
static void showSuppliers() {
242+
System.out.println("\nSuppliers:");
243+
for (Supplier supplier : suppliers)
244+
System.out.println(supplier);
245+
}
203246
}

src/app/Main.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ public static void main(String[] args) {
1010
try {
1111
boolean run = true;
1212
int chocie;
13-
while (run == true) {
13+
do {
1414
System.out.println("enter number for task: ");
15-
1615
System.out.println("Library System menu\n");
1716
System.out.println("1.) Find member by ID\n");
1817
System.out.println("2.) Find Book by ID\n");
1918
System.out.println("3.) Find supplier by ID\n");
2019
System.out.println("4.) Borrow book\n");
2120
System.out.println("5.) Purchase book\n");
22-
System.out.println("6.) show all members");
23-
System.out.println("7.) show all books");
24-
System.out.println("8.) show all suppliers");
21+
System.out.println("6.) show all members\n");
22+
System.out.println("7.) show all books\n");
23+
System.out.println("8.) show all suppliers\n");
2524
System.out.println("0.) Exit\n");
2625
System.out.println("************************************");
2726

@@ -47,19 +46,21 @@ public static void main(String[] args) {
4746
break;
4847
}
4948
case 5: {
50-
49+
// System.out.println("5.) Purchase book\n");
50+
System.out.println(App.purchaseBook());
5151
break;
5252
}
5353
case 6: {
54-
54+
// System.out.println("6.) show all members");
55+
App.showMembers();
5556
break;
5657
}
5758
case 7: {
58-
59+
App.showBooks();
5960
break;
6061
}
6162
case 8: {
62-
63+
App.showSuppliers();
6364
break;
6465
}
6566
case 0: {
@@ -71,7 +72,7 @@ public static void main(String[] args) {
7172
break;
7273
}
7374

74-
}
75+
} while (run);
7576
System.out.println("Hello Java");
7677

7778
} catch (

0 commit comments

Comments
 (0)