forked from erisean/Project-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackendDummy.java
More file actions
255 lines (217 loc) · 7.83 KB
/
Copy pathBackendDummy.java
File metadata and controls
255 lines (217 loc) · 7.83 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.Reader;
// --== CS400 File Header Information ==--
// Author: CS400 Course Staff
// Email: heimerl@cs.wisc.edu / dahl@cs.wisc.edu
// Notes: This dummy class is part of the starter archive for Project One
// in spring 2021. You can extend it to work on your Project One Final
// App.
public class BackendDummy implements BackendInterface {
/**
* This constructor instantiates a backend with the command line arguments
* passed to the app when started by the user. The arguments are expected
* to contain the path to the data file that the backend will read in.
* @param args list of command line arguments passed to front end
*/
public BackendDummy(String[] args) {
System.out.println("Dummy backend; ignoring file paths in argument");
}
/**
* A constructor that will create a backend from data that can be read in
* with a reader object.
* @param r A reader that contains the data in CSV format.
*/
public BackendDummy(Reader r) {
System.out.println("Dummy backend; ignoring data in argument");
}
/**
* Method to add a genre that the user selected. It will output but not store the
* genres passed to it.
*/
@Override
public void addGenre(String genre) {
System.out.println("Dummy backend; will ignore genre to add (" + genre + ")");
}
/**
* Method to add a genre that the user selected. It will output but not store the
* ratings passed to it.
*/
@Override
public void addAvgRating(String rating) {
// TODO: Fixme! Add dummy implementation similar to addGenre method.
System.out.println("Dummy backend; will ignore rating to add (" + rating + ")");
}
/**
* Method to remove a genre that the user selected. It will output but not remove the
* genre passed to it from the backend object.
*/
@Override
public void removeGenre(String genre) {
// TODO: Fixme! Add dummy implementation similar to addGenre method.
System.out.println("Dummy backend; will ignore genre to remove (" + genre + ")");
}
/**
* Method to remove a rating that the user selected. It will output but not remove the
* genre passed to it from the backend object.
*/
@Override
public void removeAvgRating(String rating) {
// TODO: Fixme! Add dummy implementation similar to addGenre method.
System.out.println("Dummy backend; will ignore rating to remove (" + rating + ")");
}
/**
* Return the genres added to this backend object. The dummy implementation always returns
* the same list of genres for testing.
*/
@Override
public List<String> getGenres() {
return Arrays.asList(new String [] { "Western", "Comedy", "Thriller" });
}
/**
* Return the ratings added to this backend object. The dummy implementation always returns
* the same list of ratings for testing.
*/
@Override
public List<String> getAvgRatings() {
// TODO: Fixme! Add dummy implementation similar to getGenres.
return Arrays.asList(new String [] { "9/10", "5.7/10", "8.3/10" });
}
/**
* Returns the number of movies. This is a constant for the dummy impementation.
*/
@Override
public int getNumberOfMovies() {
return 3;
}
/**
* Returns all genres in the dataset. Will return a list of 5 genres for the dummy implementation.
*/
@Override
public List<String> getAllGenres() {
return Arrays.asList(new String [] { "Western", "Comedy", "Thriller", "History", "Action" });
}
/**
* Returns the movies that match the ratings and genres. The dummy implementation will return the
* same list of three movies.
*/
@Override
public List<MovieInterface> getThreeMovies(int startingIndex) {
ArrayList<MovieInterface> movies = new ArrayList<MovieInterface>();
movies.add(new MovieInterface() {
@Override
public String getTitle() {
return "Plan 9 from Outer Spacce";
}
@Override
public Integer getYear() {
return 1959;
}
@Override
public List<String> getGenres() {
return Arrays.asList(new String[] { "Action", "Comedy" });
}
@Override
public String getDirector() {
return "Ed Wood";
}
@Override
public String getDescription() {
return "Residents of California's San Fernando Valley are under attack by flying saucers from outer space.";
}
@Override
public Float getAvgVote() {
return 5.3f;
}
@Override
public int compareTo(MovieInterface otherMovie) {
if (this.getTitle().equals(otherMovie.getTitle())) {
return 0;
// sort by rating
} else if (this.getAvgVote() < otherMovie.getAvgVote()) {
return +1;
} else {
return -1;
}
}
});
// TODO: Fixme! Add two more example movies to the list before returning it (could be
// ficticious ones).
movies.add(new MovieInterface() {
@Override
public String getTitle() {
return "Attack of the Mutant Cows";
}
@Override
public Integer getYear() {
return 1963;
}
@Override
public List<String> getGenres() {
return Arrays.asList(new String[] { "Horror" });
}
@Override
public String getDirector() {
return "Jackson McNeil";
}
@Override
public String getDescription() {
return "A space rock lands in a farmers field, and now there are mutant cows!";
}
@Override
public Float getAvgVote() {
return 4.1f;
}
@Override
public int compareTo(MovieInterface otherMovie) {
if (this.getTitle().equals(otherMovie.getTitle())) {
return 0;
// sort by rating
} else if (this.getAvgVote() < otherMovie.getAvgVote()) {
return +1;
} else {
return -1;
}
}
});
movies.add(new MovieInterface() {
@Override
public String getTitle() {
return "Velocipastor";
}
@Override
public Integer getYear() {
return 2001;
}
@Override
public List<String> getGenres() {
return Arrays.asList(new String[] { "Action", "Comedy" });
}
@Override
public String getDirector() {
return "Sam Newman";
}
@Override
public String getDescription() {
return "velociraptor + Roman Catholic Pastor = a damn good movie";
}
@Override
public Float getAvgVote() {
return 7.9f;
}
@Override
public int compareTo(MovieInterface otherMovie) {
if (this.getTitle().equals(otherMovie.getTitle())) {
return 0;
// sort by rating
} else if (this.getAvgVote() < otherMovie.getAvgVote()) {
return +1;
} else {
return -1;
}
}
});
return movies;
}
}