Lab 6: Movies

Posted: October 14, 2008

Due to be checked in class Monday 10/20/08.  Write a program that creates an array of 10 Movies and fills it with references to new Movie objects. (See page 60 if the preceding sentence is not completely clear to you — the assigned reading must be done!)  Use the following class definition for Movie:

class Movie
{
  String title;
  String genre;
  int rating;
}

 

Use array index notation and the dot operator to set the 10 titles and genres to those of any movies you choose, or that you would like to make up.

Then use a for loop to set the ratings of all movies to be random numbers from 1 to 10 and also to print out the title, genre, and rating of the movie.

After the movie names, genres, and ratings are all printed out, use a second for loop to traverse the array and find the highest rating. Sample output:

Movie: Triad Election, Genre: Hong Kong, Rating: 8
Movie: Vertigo, Genre: Film Noir, Rating: 5
Movie: The Maltese Falcon, Genre: Film Noir, Rating: 7
Movie: So I Married An Axe Murderer, Genre: Comedy, Rating: 7
Movie: eXistenZ, Genre: Drama, Rating: 3
Movie: Hero, Genre: Martial Arts, Rating: 9
Movie: Office Space, Genre: Comedy, Rating: 5
Movie: Rivers and Tides, Genre: Documentary, Rating: 2
Movie: The Fall, Genre: Drama, Rating: 6
Movie: King of Kong, Genre: Documentary, Rating: 4
Highest rated movie: Hero (9/10)

 

Extra credit: change the Movie class to allow the ratings to be numbers from 1.0 to 10.0 (note that this is a single decimal place) and set them randomly, while keeping all the previous functionality.

Extra credit part 2: In the case of a tie for maximum rating, print something like:
Tied for highest rating: The Maltese Falcon(8/10), eXistenZ (8/10)