Repository navigation
Expand file tree
/
Copy pathPeriodicalLiteratureView.java
More file actions
146 lines (113 loc) · 4.38 KB
/
Copy pathPeriodicalLiteratureView.java
File metadata and controls
146 lines (113 loc) · 4.38 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
/*
* 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;
/**
*
* @author norby
*/
public class PeriodicalLiteratureView extends View {
private String[] view
= {
"Please type in name of publisher ",
"Please type in title",
"Please type in yearly releases",
"Please enter purchase price",
"Please type in number received",
"Please enter the year this paper is published",
"Please enter the month",
"Please enter the day of month"
};
private String[] whatPeriodicalLiterature
= {
"1. Newspaper",
"2. Comic"
};
private String[] searchOptions
= {
"1. Find newspaper by publisher"
};
public PeriodicalLiteratureView(LiteratureRegister myRegister) {
super();
register = myRegister;
}
public Literature createLiterature() {
Literature periodicalLiterature = null;
System.out.println("\nPlease choose what you want to add");
int menuSelection = showMenu(whatPeriodicalLiterature);
if (menuSelection == 1) {
periodicalLiterature = userInput(menuSelection);
}
if (menuSelection == 2) {
periodicalLiterature = userInput(menuSelection);
}
System.out.print("Newspaper succesfully added\n");
return periodicalLiterature;
}
/**
* creates a new instance of periodical literature
*
*
*
* @param selection
* @return Literature
*/
private Literature userInput(int selection) {
String publisher = "no title added";
Literature literature = null;
switch (selection) {
case 1:
System.out.println(view[0]);
publisher = validInput.checkString();
System.out.println(view[2]);
int yearlyReleases = validInput.checkInt(1, 365);
System.out.println(view[3]);
long purchasePrice = validInput.checkInt(0, 999);
System.out.println(view[4]);
int numberReceived = validInput.checkInt(1, 99);
System.out.println(view[5]);
int year = validInput.checkInt(1000, 3000);
System.out.println(view[6]);
int month = validInput.checkInt(1, 12);
System.out.println(view[7]);
int dayOfMonth = validInput.checkInt(1, 31);
if (!validInput.testDate(year, month, dayOfMonth)) {
System.out.println("Date Error. instance was not added\n");
}
literature = new Newspaper(publisher, yearlyReleases, purchasePrice, numberReceived, year, month, dayOfMonth);
break;
case 2:
System.out.println(view[0]);
publisher = validInput.checkString();
System.out.println(view[1]);
String title = validInput.checkString();
System.out.println(view[2]);
yearlyReleases = validInput.checkInt(1, 365);
System.out.println(view[3]);
purchasePrice = validInput.checkInt(0, 999);
System.out.println(view[4]);
numberReceived = validInput.checkInt(1, 99);
System.out.println(view[5]);
year = validInput.checkInt(1000, 3000);
System.out.println(view[6]);
month = validInput.checkInt(1, 12);
System.out.println(view[7]);
dayOfMonth = validInput.checkInt(1, 31);
if (!validInput.testDate(year, month, dayOfMonth)) {
System.out.println("Date Error. instance was not added\n");
}
literature = new Comics(publisher, title, yearlyReleases, purchasePrice, numberReceived, year, month, dayOfMonth);
break;
}
return literature;
}
@Override
public void getSearchOptions() {
int menuSelection = showMenu(searchOptions);
if (menuSelection == 1) {
findPeriodicalLiteratureByPublisher();
}
}
}