Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.lepackage;
- public class Movie {
- String movieName;
- String MPAA;
- //int movieRate;
- int terrible = 0, bad = 0, ok = 0, good = 0, great = 0;
- public Movie(){
- }
- public Movie(String name, String mpaa){
- movieName = name;
- MPAA = mpaa;
- }
- public void setMovieName(String name){
- movieName = name;
- }
- public String getMovieName(){
- return movieName;
- }
- public void addRating(int rate){
- switch(rate){
- case 1:
- terrible++;
- break;
- case 2:
- bad++;
- break;
- case 3:
- ok++;
- break;
- case 4:
- good++;
- break;
- case 5:
- great++;
- break;
- default:
- System.out.println("Error, you've entered a wrong rate value.");
- break;
- }
- }
- public double getAverage(){
- int sum, people;
- double average;
- sum = (terrible) + (bad * 2) + (ok * 3) + (good * 4) + (great * 5);
- people = terrible + bad + ok + good + great;
- average = (double)sum / (double)people;
- return average;
- }
- public void display(){
- System.out.println("Movie Name: " + movieName);
- System.out.println("MPAA: " + MPAA);
- System.out.println("Rate : " + getAverage());
- }
- }
- package com.lepackage;
- public class Main {
- public static void main(String[] args) {
- Movie movie1 = new Movie("Movie 1", "PG-13");
- movie1.addRating(5);
- movie1.addRating(3);
- movie1.addRating(5);
- movie1.addRating(4);
- movie1.addRating(5);
- movie1.addRating(2);
- movie1.addRating(5);
- movie1.addRating(1);
- movie1.addRating(5);
- movie1.addRating(2);
- movie1.display();
- }
- }
Add Comment
Please, Sign In to add comment