Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider a class Movie that contains information about a movie. The class has the following attributes: The movie name The MPAA rating (e.g., G, PG,

Consider a class Movie that contains information about a movie. The class has the following attributes:

The movie name

The MPAA rating (e.g., G, PG, PG-13, R)

The number of people who have rated this movie as a 1 (Terrible)

The number of people who have rated this movie as a 2 (Bad)

The number of people who have rated this movie as a 3 (OK)

The number of people who have rated this movie as a 4 (Good)

The number of people who have rated this movie as a 5 (Great)

Implement the class with accessors and mutators for the movie name and MPAA rating. Write a method addRating that takes an integer as an input parameter. The method should verify that the parameter is a number between 1 and 5, and if so, increment by one the number of people rating the movie that matches the input parameter. For example, if 3 is the input parameter, then the number of people who rated the movie as a 3 should be incremented by one. Write another method, getAverage, that returns the average value for all of the movie ratings. Note: if there are no ratings for a movie then the average value should be 0.

Test the class by writing a main method that creates at least two Movie objects, adds at least five ratings for each movie, and outputs the movie name, MPAA rating, and average rating for each Movie object; your output lines should look just like this:

movie-name,movie-MPAA-rating Average rating: average-of-customer-ratings 

Hint: There is an online videonote regarding a solution for Project 10.

IN JAVA:

public class Movie

{

private String name;

private String ratingMPAA;

// create setters and getters for the above two instance variables

/* your code goes here */

private int numRated1 = 0, numRated2 = 0, numRated3 = 0, numRated4 = 0, numRated5 = 0;

public void addRating(int num)

{

/* your code goes here */

}

public double getAverage()

{

// be careful of integer division in this method!!

/* your code goes here */

}

public static void main(String[] args)

{

// add tests for your Movies here

/* your code goes here */

/* DO NOT MODIFY THE LINES BELOW THIS COMMENT */

Movie m1 = new Movie();

m1.setName("The Adjustment Bureau");

m1.setRating("PG-13");

m1.addRating(5);

m1.addRating(5);

m1.addRating(4);

m1.addRating(4);

m1.addRating(5);

System.out.println(m1.getName() + "," + m1.getRating() +

" Average rating: " + m1.getAverage());

Movie m2 = new Movie();

m2.setName("I Am Number Four");

m2.setRating("PG-13");

m2.addRating(3);

m2.addRating(2);

m2.addRating(2);

m2.addRating(4);

m2.addRating(1);

System.out.println(m2.getName() + "," + m2.getRating() +

" Average rating: " + m2.getAverage());

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

Students also viewed these Databases questions

Question

3. What information do participants need?

Answered: 1 week ago