Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

logo Practice-It logo

rateMovies

Language/Type: Java file processing Scanner
Author: Marty Stepp (on 2020/04/08)

Write a static method called rateMovies that takes a Scanner containing movie ratings as a parameter, and prints statistics about each movie. The input will have one movie entry per line. Each line has an integer n indicating how many ratings there are, followed by the n different ratings for the movie. Each line ends with the title of the movie. For example, the input might contain the following:

   4 9.2 9 8.5 9.5 Seven Samurai (1954)
   5 8.2 9.5 7 10 9.8 12 Angry Men (1957)
   6 5.7 6 9 9 8 10 Fight Club (1999)

The method should read each line of the file, printing one line of output for each movie entry. Each line of output should list the movie title, the number of ratings, and the score (the average of the ratings). For the input above, it should produce the following output:

title = Seven Samurai (1954), ratings = 4, score = 9.05
title = 12 Angry Men (1957), ratings = 5, score = 8.9
title = Fight Club (1999), ratings = 6, score = 7.95

You are to exactly reproduce the format of this output. You may assume that the number of ratings is always at least 1.

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.