logo Practice-It logo


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.