Cs1020 sit in lab 2 discussion
This presentation is the property of its rightful owner.
Sponsored Links
1 / 11

CS1020 Sit In Lab 2 Discussion PowerPoint PPT Presentation


  • 144 Views
  • Uploaded on
  • Presentation posted in: General

CS1020 Sit In Lab 2 Discussion. Movie Rating System. To understand the object oriented programming concept by building a “Movie Rating System” that manages the category and rating of movies. Functions needed BestMovie <category> WorstMovie <category> AverageRating <category> mostVote.

Download Presentation

CS1020 Sit In Lab 2 Discussion

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Cs1020 sit in lab 2 discussion

CS1020Sit In Lab 2 Discussion


Movie rating system

Movie Rating System

  • To understand the object oriented programming concept by building a “Movie Rating System” that manages the category and rating of movies.

  • Functions needed

    • BestMovie <category>

    • WorstMovie <category>

    • AverageRating <category>

    • mostVote


Examples

Examples

  • 2// Number of CategoriesActionComedy3// Number of MoviesBatman Action// <Movie name> <Category>TheDictatorComedySuperman Action7// Number of Commandsvote Batman 3vote Superman 2averageRating Action// output: 3averageRating Comedy// output: 0bestMovie Action// output: BatmanworstMovie Action// output: SupermanmostVote// output: Batman


Breaking down the problem

Breaking down the problem!

  • 1. Read and process the input

  • 2. What are the required data members in each classes?

    • List of movies in Category class?

    • Variables to store category name, totalVote and voters in Movie class?

  • 3. How to keep track of the average rating?

  • 4. Output result


Step 1 read process input

Step 1: Read & Process Input

  • Use Scanner object for input

  • Three parts to reading input

    • Read the number of categories (int) and use a loop to add them to our MovieSystem class

    • Likewise for adding all the movies//loopMovie m = new Movie(sc.next());movieSystem.addMovie(m);movieSystem.getCategoryFromName(sc.next()).addMovie(m);

    • Read the number of commands (int), and use a loop to read the specific operation ( String ) needed

      • e.g. String operation = sc.next(); if ( operation.equals( “vote” ) ) // do the necessary processing . . .


Step 2 what are required data members for each class

Step 2: What are required data members for each class?

MovieSystem

- categories: List <Category>

- movies: List <Movie>

+ addMovie(movie: Movie)

+ addVote(movie: String, rating: int)

+ bestMovie(category: String) : String

+ worstMovie(category: String) : String

+ avgRating(category: String) : double

+ mostVote() : String

Movie

- name: String

- category: String

- totalVote: int

- voters: int

+ addVote(vote: int)

+ getAvgRating() : double

Category

- name: String

- movies: List <Movie>

+ add(movie: Movie)

+ bestMovie() : String

+ worstMovie() : String

+ getAvgRating() : double

  • * the above listed does not the ALL the methods


Cs1020 sit in lab 2 discussion

Movie

Movie

MovieSystem

Movie

Category

Movie

List of movies

List of movies

Movie

Movie

List of categories

Category

Movie

Movie

List of movies

Movie

Category

List of movies


Step 3a keeping track of average rating

Step 3a: Keeping track of Average Rating

  • Movie class (average rating of a movie)if (voters==0) return 0; //avoid division by 0return (double)totalVote / (double)voters;

  • Category class (average rating of a category)if (movies.size()==0) return 0; //avoid division by 0double total=0;for(int i=0; i<movies.size(); i++)total += movies.get(i).getAvgRating();return total / movies.size();


Step 3b best worst movie most votes

Step 3b: Best & Worst Movie? Most Votes?

  • Movie with the mostVote can be solved in MovieSystemClass by iterating through all movies in the movie list and checking their amount of votes

  • Best & Worst Movie in a Category can be solved in Category class by iterating through all movies in that categoryfor (int i=0; i<movies.size(); i++) {

    if( bestMovie==null || movies.get(i).getAvgRating() > bestMovie.getAvgRating())bestMovie = movie.get(i);}


Step 4 output result

Step 4: Output result

  • For output, we will use our MovieSystem classe.g. to print the average rating of a category

    public double avgRating(String category) {return getCategory(category).getAvgRating();

    }

  • Print what is returned by the above function

    System.out.printf("%.0f\n", movieSystem.avgRating(sc.next()));

    System.out.println(Math.round(

    movieSystem.avgRating(sc.next())));

Regarding printf, see:

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html#syntax


That s all

That’s all!


  • Login