Consider a class Movie that contains information about a mov

Consider a class Movie that contains information about a movie. The class has the following attributes: The movie name The MPAA rating (G, PG, etc) The number of 1-st ar reviews The number of 2-star reviews The number of 3¯star reviews The number of 4¯star reviews The number of 5-star reviews Implement this class and create the following methods: An accessor and mutator (also called getters and setters, respectively) for the movie name. An accessor and imitator (also called getters and setters, respectively) for the MPAA rating. addReview(int stars) that takes in an integer as an input parameter. The method should verify if the parameter is between 1 and 5. and if so, increment the number of reviews with that many stars by one. Write another method. getAverage(), which returns then average value for all the reviews. 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, the MPAA rating, and the average rating of each movie object.

Solution

package chegg;

public class Movie {
  
   String movieName;
   public String getMovieName() {
       return movieName;
   }

   public void setMovieName(String movieName) {
       this.movieName = movieName;
   }

   public String getMPAA() {
       return MPAA;
   }

   public void setMPAA(String mPAA) {
       MPAA = mPAA;
   }

   String MPAA;
   int one_star=0;
   int two_star=0;
   int three_star=0;
   int four_star=0;
   int five_star=0;
  
   int addReview(int stars){
      
      
       if(stars>1 && stars<=5){
           if(stars==1){
               one_star++;
           }
           if(stars==2){
               two_star++;
           }
           if(stars==3){
               three_star++;
           }if(stars==4){
               four_star++;
           }
           if(stars==5){
               five_star++;
           }
       }
       return 1;
   }
  
   int getAverage(){
       int avg= (one_star+two_star+three_star+four_star+five_star/5);
       return avg;
   }
  
   public static void main(String args[]){
       Movie m = new Movie();
       m.setMovieName(\"Avengers\");
       m.setMPAA(\"G\");
       m.addReview(2);
       m.addReview(3);
       m.addReview(3);
       m.addReview(4);
       m.addReview(4);
      
       System.out.println(m.getMovieName());
       System.out.println(m.getMPAA());
       System.out.println(m.getAverage());
      
       Movie m1 = new Movie();
       m1.setMovieName(\"Die Another Day\");
       m1.setMPAA(\"PG\");
       m1.addReview(4);
       m1.addReview(3);
       m1.addReview(3);
       m1.addReview(4);
       m1.addReview(5);
      
       System.out.println(m1.getMovieName());
       System.out.println(m1.getMPAA());
       System.out.println(m1.getAverage());
      
      
   }

}

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site