콘텐츠로 이동

Mini Project Set 3: Movie Rating Dashboard

Name: ________

Time: 40 minutes

Write a Java program that stores ratings for five movies and prints a small dashboard. A rating is an integer from 1 to 5.

Learning Goals

  • Use parallel arrays to keep related data together.
  • Search an array and remember the index of a best value.
  • Combine loops, conditionals, strings, and formatted output.
  • Write and call a helper method.

Data to Use

Use these two arrays exactly as shown. The title at each index belongs to the rating at the same index.

String[] titles = {"Sky Route", "Moonlight Cafe", "Code Quest", "Ocean Signal", "Last Train"};
int[] ratings = {4, 5, 3, 5, 2};

Requirements

  • Write a method with this exact header:
public static String stars(int rating)

It returns a string containing rating asterisks. For example, stars(3) returns "***". - In main, use one loop over the arrays to find: - the total of all ratings - the index of the first highest-rated movie - the number of recommended movies (rating 4 or 5) - Print one line for each movie in this format:

Sky Route: **** (4)
  • Then print the dashboard summary. The average must have two decimal places.
  • When two movies have the same highest rating, keep the first one. Do not replace the best index for an equal rating.

Expected Output

Sky Route: **** (4)
Moonlight Cafe: ***** (5)
Code Quest: *** (3)
Ocean Signal: ***** (5)
Last Train: ** (2)
Average rating: 3.80
Top movie: Moonlight Cafe
Recommended movies: 3

Starter Code

public class Main {
    public static String stars(int rating) {
        // TODO
        return "";
    }

    public static void main(String[] args) {
        String[] titles = {"Sky Route", "Moonlight Cafe", "Code Quest", "Ocean Signal", "Last Train"};
        int[] ratings = {4, 5, 3, 5, 2};

        // TODO: Initialize summary variables.
        // TODO: Use one loop to print each movie and update the summary values.
        // TODO: Print the summary.
    }
}

Before You Submit

  • Start bestIndex at 0 because the first movie is initially the best candidate.
  • Use > instead of >= when comparing a rating to the current highest rating.
  • Build the stars string with a loop; do not type separate cases for ratings 1 through 5.