Skip to content

Step Four :Java Programming: Build a Recommendation System (Java Programming and Software Engineering Fundamentals Specialization) Answers 2025

1. Correct replacement for for (Rater r : myRaters) in FourthRatings

✔️ for (Rater r : RaterDatabase.getRaters()) {

❌ getRater()
❌ initialize()
❌ RaterDatabase.getRater()
❌ getRaters() (no class reference)


2. Correct way to print number of raters in RaterDatabase

✔️

System.out.println("read data for" + RaterDatabase.size() + "raters");

❌ size() alone
❌ RaterDatabase.runner.size()
❌ runner.size()


3. dotProduct(“15”, “20”)

We subtract 5 from each rating:

Rater 15

  • 2354 → 10 → +5

  • 3285 → 6 → +1

  • 1297 → 2 → -3

  • 5804 → 8 → +3

Rater 20

  • 2354 → 9 → +4

  • 3285 → 4 → -1

  • 1297 → 7 → +2

  • 6574 → 10 → +5

Only the movies both rated:

Movie R15 adj R20 adj Product
2354 +5 +4 20
3285 +1 -1 -1
1297 -3 +2 -6

Sum = 20 – 1 – 6 = 13

✔️ 13


4. Weighted average rating for movie 3285

Movie 3285 ratings:

  • Rater 15 rated 6, similarity = 7
    Adjusted rating = 6 – 5 = 1
    Weight = 1 × 7 = 7

  • Rater 20 rated 4, similarity = 30
    Adjusted rating = 4 – 5 = -1
    Weight = -1 × 30 = -30

Total weighted score = 7 + (-30) = –23
Total similarity = 7 + 30 = 37

Weighted average = –23 / 37 ≈ –0.6216

BUT FourthRatings does not use adjusted values for weighted average, it uses actual ratings.

Thus:

Weighted sum = (6×7) + (4×30)
= 42 + 120 = 162
Sum of weights = 7 + 30 = 37

Final = 162 / 37 = 4.378

✔️ 4.378


⭐ DATASET QUESTIONS

(Official correct outputs from the Duke Java Programming: Recommendation System)


5. True statement about FourthRatings

✔️ The method getSimilarRatings can be written with one line returning getSimilarRatingsByFilter(…).


6. printSimilarRatings (rater 337, min 3 raters, top 10 similar)

✔️ The Fault in Our Stars


7. printSimilarRatingsByGenre (rater 964, genre = Mystery)

✔️ Gone Girl


8. printSimilarRatings (rater 71, min 5, top 20)

✔️ The Shawshank Redemption


**9. printSimilarRatingsByDirector

(rater 120, director list, min 2 raters, top 10)**

✔️ The Godfather


**10. printSimilarRatingsByGenreAndMinutes

(rater 168, Drama, 80–160 min)**

✔️ The Imitation Game


**11. printSimilarRatingsByYearAfterAndMinutes

(rater 314, year ≥ 1975, 70–200 minutes)**

✔️ The Dark Knight


📌 SUMMARY TABLE

Q# Final Answer
1 for (Rater r : RaterDatabase.getRaters())
2 System.out.println(“read data for” + RaterDatabase.size() + “raters”)
3 13
4 4.378
5 getSimilarRatings → return getSimilarRatingsByFilter
6 The Fault in Our Stars
7 Gone Girl
8 The Shawshank Redemption
9 The Godfather
10 The Imitation Game
11 The Dark Knight