Skip to content

Commit 44e2798

Browse files
committed
Week2. a new class MovieRunnerAverage
1 parent da8f5b9 commit 44e2798

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

Week1/src/FirstRatings.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ public ArrayList<Rater> getRaterArrayList() {
2424
}
2525

2626
private ArrayList<Movie> movieArrayList;
27+
28+
/**
29+
* This method returns number of unique Raters
30+
*
31+
* @return int number of unique raters
32+
*/
33+
public int getRatersNumber() {
34+
return ratersWithIds.size();
35+
}
36+
2737
private ArrayList<Rater> raterArrayList;
2838

2939
private HashMap<String, HashSet<String>> directorsAndItsMovies;

Week2/src/MovieRunnerAverage.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class MovieRunnerAverage {
2+
3+
public MovieRunnerAverage() {}
4+
5+
public void printAverageRatings() {
6+
SecondRatings secondRatings = new SecondRatings("ratedmovies_short.csv", "ratings_short.csv");
7+
System.out.printf(
8+
"Total number of movies %d, total number of raters %d",
9+
secondRatings.getMovieSize(), secondRatings.getRaterSize());
10+
}
11+
}

Week2/src/SecondRatings.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public class SecondRatings {
1111
private final ArrayList<Movie> myMovies;
1212
private final ArrayList<Rater> myRaters;
13+
private final FirstRatings firstRatings;
1314

1415
public SecondRatings() {
1516
// default constructor
@@ -20,7 +21,7 @@ public SecondRatings() {
2021
// loadRaters methods in FirstRatings to read in all the movie and ratings data and store them
2122
// in the two private ArrayList variables of the SecondRatings class, myMovies and myRaters.
2223
public SecondRatings(String moviesFileName, String ratingsFileName) {
23-
FirstRatings firstRatings = new FirstRatings(moviesFileName, ratingsFileName);
24+
firstRatings = new FirstRatings(moviesFileName, ratingsFileName);
2425
myMovies = firstRatings.getMovieArrayList();
2526
myRaters = firstRatings.getRaterArrayList();
2627
}
@@ -42,6 +43,6 @@ public int getMovieSize() {
4243
* @return int number of movies
4344
*/
4445
public int getRaterSize() {
45-
return this.myRaters.size();
46+
return this.firstRatings.getRatersNumber();
4647
}
4748
}

Week2/src/Week2.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class Week2 {
2+
public static void main(String[] args) {
3+
MovieRunnerAverage average = new MovieRunnerAverage();
4+
average.printAverageRatings();
5+
}
6+
}

0 commit comments

Comments
 (0)