ZazoTazo

Movie

Nov 29th, 2019
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. package com.lepackage;
  2.  
  3. public class Movie {
  4.     String movieName;
  5.     String MPAA;
  6.     //int movieRate;
  7.     int terrible = 0, bad = 0, ok = 0, good = 0, great = 0;
  8.  
  9.     public Movie(){
  10.  
  11.     }
  12.  
  13.     public Movie(String name, String mpaa){
  14.         movieName = name;
  15.         MPAA = mpaa;
  16.     }
  17.  
  18.     public void setMovieName(String name){
  19.         movieName = name;
  20.     }
  21.  
  22.     public String getMovieName(){
  23.         return movieName;
  24.     }
  25.  
  26.     public void addRating(int rate){
  27.         switch(rate){
  28.             case 1:
  29.                 terrible++;
  30.                 break;
  31.             case 2:
  32.                 bad++;
  33.                 break;
  34.             case 3:
  35.                 ok++;
  36.                 break;
  37.             case 4:
  38.                 good++;
  39.                 break;
  40.             case 5:
  41.                 great++;
  42.                 break;
  43.             default:
  44.                 System.out.println("Error, you've entered a wrong rate value.");
  45.                 break;
  46.         }
  47.     }
  48.  
  49.     public double getAverage(){
  50.         int sum, people;
  51.         double average;
  52.         sum = (terrible) + (bad * 2) + (ok * 3) + (good * 4) + (great * 5);
  53.         people = terrible + bad + ok + good + great;
  54.         average = (double)sum / (double)people;
  55.         return average;
  56.     }
  57.  
  58.     public void display(){
  59.         System.out.println("Movie Name: " + movieName);
  60.         System.out.println("MPAA: " + MPAA);
  61.         System.out.println("Rate : " + getAverage());
  62.     }
  63. }
  64.  
  65.  
  66.  
  67. package com.lepackage;
  68.  
  69. public class Main {
  70.  
  71.     public static void main(String[] args) {
  72.         Movie movie1 = new Movie("Movie 1", "PG-13");
  73.         movie1.addRating(5);
  74.         movie1.addRating(3);
  75.         movie1.addRating(5);
  76.         movie1.addRating(4);
  77.         movie1.addRating(5);
  78.         movie1.addRating(2);
  79.         movie1.addRating(5);
  80.         movie1.addRating(1);
  81.         movie1.addRating(5);
  82.         movie1.addRating(2);
  83.         movie1.display();
  84.     }
  85. }
Add Comment
Please, Sign In to add comment