-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookview.java
More file actions
181 lines (134 loc) · 4.67 KB
/
Copy pathBookview.java
File metadata and controls
181 lines (134 loc) · 4.67 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gruppeinnlevering;
import java.util.Iterator;
/**
*
* @author norby
*/
public class Bookview extends View {
private Validator validInput;
private LiteratureRegister register;
private String[] view
= {
"Please type in name of publisher",
"Please type in title",
"Please type in author",
"Please type in genre",
"Please enter purchase price",
"Please type in number received",
"Please enter the year this Book was published",
"Please enter the month",
"Please enter the day of month"
};
private String[] searchOptions
= {
"1. Find book by title",
"2. Find book by author"
};
public Bookview(LiteratureRegister myRegister) {
super();
register = myRegister;
validInput = new Validator();
}
/**
* creates an instance of book. the user get the choice of adding it ¨to a
* series.
*
* @return Literature
*/
public Literature createLiterature() {
String publisher = "no title added";
Literature book = null;
System.out.println(view[0]);
publisher = validInput.checkString();
System.out.println(view[1]);
String title = validInput.checkString();
System.out.println(view[2]);
String author = validInput.checkString();
System.out.println(view[3]);
String genre = validInput.checkString();
System.out.println(view[4]);
int purchasePrice = validInput.checkInt(1, 1000);
System.out.println(view[5]);
int numberReceived = validInput.checkInt(1, 200);
System.out.println(view[6]);
int year = validInput.checkInt(1000, 3000);
System.out.println("Is this book a part of a series? y/n");
String choise = validInput.checkString();
if (choise.equals("y")) {
System.out.println("\nSeries in store: \n");
while (register.getIteratorOfSeries().hasNext()) {
System.out.println("|" + register.getIteratorOfSeries().next() + "|\n");
}
System.out.println("\nplease type in name of Series\n");
String series = validInput.checkString();
try {
book = new BookSeries(
publisher,
title,
author,
genre,
series,
purchasePrice,
numberReceived,
year);
System.out.print("\nBook succesfully added\n");
} catch (IllegalArgumentException e) {
}
}
if (choise.equals("n")) {
book = new BookStandAlone(
publisher,
title,
author,
genre,
purchasePrice,
numberReceived,
year);
System.out.print("\nBook succesfully added\n");
}
return book;
}
/**
* user can find book by searching for author
*/
void findBookByAuthor() {
System.out.println("type in name of author");
String searchString = validInput.stringScanner();
Iterator<Literature> search = register.getIteratorAuthor(searchString);
if (!search.hasNext()) {
System.out.println("Sorry Bro,couldn't find what you were looking for. Please try again");
}
while (search.hasNext()) {
System.out.println(getDetails(search.next()));
}
}
/**
* User vcan find Book by searching for title
*/
void findByTitle() {
System.out.println("type in title name");
String searchString = validInput.stringScanner();
Iterator<Literature> search = register.getIteratorTitle(searchString);
if (!search.hasNext()) {
System.out.println("Sorry Bro,couldn't find what you were looking for. Please try again");
}
while (search.hasNext()) {
System.out.println(getDetails(search.next()));
}
}
@Override
public void getSearchOptions() {
int menuSelection = showMenu(searchOptions);
if (menuSelection == 1) {
findByTitle();
}
if (menuSelection == 2) {
findBookByAuthor();
}
}
}