@@ -121,9 +121,7 @@ private static Member createNewMember() {
121
121
122
122
static Member getMember () throws InterruptedException {
123
123
124
- System .out .println ("\n members:" );
125
- for (Member member : members )
126
- System .out .println (member );
124
+ showMembers ();
127
125
System .out .print ("enter ID to search: " );
128
126
int id = scan .nextInt ();
129
127
boolean found = false ;
@@ -151,9 +149,7 @@ static Member getMember() throws InterruptedException {
151
149
152
150
static Book getBook () throws InterruptedException {
153
151
154
- System .out .println ("\n Books:" );
155
- for (Book book : books )
156
- System .out .println (book );
152
+ showBooks ();
157
153
System .out .print ("enter ID to search: " );
158
154
int id = scan .nextInt ();
159
155
boolean found = false ;
@@ -177,9 +173,7 @@ static Book getBook() throws InterruptedException {
177
173
178
174
static Supplier getSupplier () throws InterruptedException {
179
175
180
- System .out .println ("\n Suppliers:" );
181
- for (Supplier supplier : suppliers )
182
- System .out .println (supplier );
176
+ showSuppliers ();
183
177
System .out .print ("enter ID to search: " );
184
178
int id = scan .nextInt ();
185
179
boolean found = false ;
@@ -200,4 +194,53 @@ static Supplier getSupplier() throws InterruptedException {
200
194
}
201
195
return null ;
202
196
}
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 ("\n members:" );
231
+ for (Member member : members )
232
+ System .out .println (member );
233
+ }
234
+
235
+ static void showBooks () {
236
+ System .out .println ("\n Books:" );
237
+ for (Book book : books )
238
+ System .out .println (book );
239
+ }
240
+
241
+ static void showSuppliers () {
242
+ System .out .println ("\n Suppliers:" );
243
+ for (Supplier supplier : suppliers )
244
+ System .out .println (supplier );
245
+ }
203
246
}
0 commit comments