Inf1 OP : Lab Sheet Week 9 Q1 - Video Store
Overview

The goal of this exercise is to design and implement a simple inventory control system for a small video rental store.

Note

This exercise was designed by someone who still remembers what a video tape was. If the term ‘video’ bothers you, think ‘DVD’ instead.

Here is a summary of the design specification:

  • Store a library of videos identified by title.
  • Allow a video to indicate whether it is currently rented out.
  • Allow users to rate a video and display the average rating for the video.
  • Get a list of all the videos that are currently checked out of the store.
  • Find the video which has been rated most highly by users.

You will define two classes: a Video class to model a video and a class VideoStore class to model the store.

Videos

Assume that an object of class Video has the following attributes:

  • a title;
  • a boolean flag to say whether it is checked out or not.

You will need to add instance variables for these attributes to the Video class. In addition, you will need to store information about the ratings which the video has received. The API for the class Video is as follows:

public Video(String title)
Class constructor
public String getTitle()
Return the video’s title.
public boolean addRating(int rating)
Add a rating for the video. If rating is between 1-5 inclusive, then update the ratings for this video, keeping track of how many ratings for it have been received, and return true. Otherwise, print out an error message and return false.
public double getAverageRating()
Return the average rating for this video. Although ratings are always integers, the average should be a double. Return zero if no ratings have been added;
public boolean checkOut()
If the video is already checked out, warn the user and return false. Otherwise change the status of the video to checked out, and return true.
public boolean returnToStore()
If the video is not checked out, warn the user and return false. Otherwise change the status of the video to not checked out, and return true.
public boolean isCheckedOut()
Return the checked-out status of the video
public String toString()
Return a String of the form Video[title="<title>", checkedOut=<status>].

An automated test has been created for this exercise: VideoTest.java.

Video Store

The VideoStore class should contain an ArrayList containing all the videos in the store’s inventory, and has the following API:

public boolean addVideo(String title)
Add a video by title to the inventory. If there is already a video with that title in the store’s inventory, print out an error message and return false. Otherwise, add a new video with that title and return true.
public Video getVideo(String title)
Return the video whose title is title. If there is no video in the inventory with that title, print out an error message and return null.
public boolean checkOutVideo(String title)
Check out a video by title. If there is a video with that title not already checked out, change its status to checked out and return true. Otherwise, print out an appropriate error message and return false.
public boolean returnVideo(Video video)
Return the result of calling the returnToStore() method on the video.
public void rateVideo(Video video, int rating)
Add the rating rating to the video.
public double getAverageRatingForVideo(Video video)
Return the average user rating for this video as a double.
public Video[] getCheckedOut()
Return an array of type Video[] consisting of all videos in the store which have been checked out.
public Video mostPopular()
Return the video which has the highest average ranking. If there is a tie, return the first one. If the store is not stocking any videos, return null;

You are advised to create a VideoStoreTester class with a main() method which will test the functionality of your two classes. Try to test all your methods.

An automated test has been created for this exercise: VideoStoreTest.java.