Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Movie Name: MPAA Rating: Number of People Rating this movie: 10 Consider a class

ID: 3830269 • Letter: M

Question


Movie Name:
MPAA Rating:
Number of People Rating this movie:
10 Consider a class Movie that contains information about a movie. The class has the following attributes: The movie name The MPAA rating (eg G, PC, 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 a3(oK) The number of people who have rated this movie as a (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 veriy 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 eample, if3 is the input parameter, then the number of people who rated the movie as a3should be incremented by one. Write another method getAverage, that returns the average value for all of the movie ratings. 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. MOVIE NAME MPAA EATING

Explanation / Answer

PROGRAM CODE:

package util;

public class Movie {

  

   String movieName;

   String MPAARating;

   int numRating1;

   int numRating2;

   int numRating3;

   int numRating4;

   int numRating5;

  

   Movie(String name, String mpaa)

   {

       this.movieName = name;

       this.MPAARating = mpaa;

   }

   public String getMovieName() {

       return movieName;

   }

   public void setMovieName(String movieName) {

       this.movieName = movieName;

   }

   public String getMPAARating() {

       return MPAARating;

   }

   public void setMPAARating(String mPAARating) {

       MPAARating = mPAARating;

   }

  

   public void addRating(int rating)

   {

       if(rating>=1 && rating<=5)

       {

           switch(rating)

           {

           case 1: numRating1++;break;

           case 2: numRating2++;break;

           case 3: numRating3++;break;

           case 4: numRating4++;break;

           case 5: numRating5++;break;

           }

       }

   }

  

   public double getAverage()

   {

       int totalNumberOfPeople = numRating1 + numRating2 + numRating3 + numRating4 + numRating5;

       int sum = numRating1;

       sum += numRating2 *2;

       sum += numRating3 *3;

       sum += numRating4 *4;

       sum += numRating5 *5;

       return sum/totalNumberOfPeople;

      

   }

}

package util;

public class MovieDriver {

   public static void main(String[] args) {

       Movie notebook = new Movie("The NoteBook", "G");

       notebook.addRating(4);

       notebook.addRating(5);

       notebook.addRating(4);

       notebook.addRating(5);

       notebook.addRating(3);

       notebook.addRating(4);

       System.out.println("Movie Name: " + notebook.getMovieName());

       System.out.println("MPAA Rating: " + notebook.getMPAARating());

       System.out.println("Number of People Rating this movie: " + notebook.getAverage());

       Movie spiderman = new Movie("SpiderMan", "PG");

       spiderman.addRating(5);

       spiderman.addRating(4);

       spiderman.addRating(4);

       spiderman.addRating(5);

       spiderman.addRating(5);

       spiderman.addRating(3);

       System.out.println("Movie Name: " + spiderman.getMovieName());

       System.out.println("MPAA Rating: " + spiderman.getMPAARating());

       System.out.println("Number of People Rating this movie: " + spiderman.getAverage());

   }

}

OUTPUT:

Movie Name: The NoteBook

MPAA Rating: G

Number of People Rating this movie: 4.0

Movie Name: SpiderMan

MPAA Rating: PG

Number of People Rating this movie: 4.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote