CPSC-115 Fall 2008
Lab 8
October 19, 2008
Professor Heidi Ellis

Be sure that you hand in the printouts of your work before leaving!!!

Objective:

Prelab: Write complete method headers for all of the methods shown in the UML diagram for the Video class shown below.

Remember in lab 2 that we worked with videos similar to those that are posted on YouTube. Remember that in order to represent a video, we had to create six different variables. And in order to represent three videos, we had to create eighteen (18) separate variables. In this lab, you will create a Video class that contains instance variables for video data as well as methods to manipulate the data. You will also create a VideoDriver class to test the Video class.

Pair Programming:

  1. Locate your partner and introduce yourself:
  2. Kristen AndersonGreg Vaughan  Jake ElderRyan Ersland
    Jin Feng LiuJohn Wilsterman  Catherine DoyleJeffrey Young
    Nick DraguJesse Vasquez  Chelsea Bainbridge-DonnerCorazon Irizarry
  3. Select one person to start as "driver". This person will type at the keyboard for the first 20 mintues.
  4. Proceed through the process of completing the lab as described below. Be very careful to ensure that every item for both programs is completed.
  5. Swap pairs every 20 minutes.
  6. When you are done, be sure to email a copy of the code to the person whose account you are not working in. In other words, make sure that both partners have a copy of the code.
In this lab, you will create a Video class which represents a single video like one posted on YouTube. You may want to remind yourself of video information from Lab 2. Remember that a class contains attributes or fields to hold the data as well as methods to manipulate the data. Below is the UML diagram for the Video class:

Video
- id: String
- author: String
- length: int
- size: int
- rating: double
- tag: String
+ SECONDS_PER_MINUTE = 60: int
+ KB_PER_MB = 1024: int
+ Video(id: String, author: String, length: int, size: int, rating: double, tag: String)
+ setId(id: String): void
+ setAuthor(author: String): void
+ setLength(length: int): void
+ setSize(size: int): void
+ setRating(rating: double): void
+ setTag(tag: String): void
+ getId(): String
+ getAuthor(): String
+ getLength(): int
+ getSize(): int
+ getRating(): double
+ getTag(): String
+ lengthInMinutesAndSeconds(): String
+ sizeInMB(): String
+ toString(): String
+ isEqual(other: Video): boolean


You must implement the class as specified in the UML class diagram above. The toString method should construct a string that displays the data for an object with an appropriate message. This string should then be returned to the calling method.

The lengthInMinutesAndSeconds and sizeInMB methods are used to help format output by providing a string representation of the length of a video in minutes and seconds and the size in MB. The toString method should call these two methods to return a string representation of the video. An example of calling System.out.println(myVideo.toString()); might look like:

ID: 123 Author: Sam Spade Length: 24:14 Size: 10.964 MB Rating: 4.5 Tag: mystery
You must create a VideoDriver class. The only thing that the VideoDriver class contains is a main method. Your main method should:
  1. Create four instances of a Video. You will need to use the new command followed by the data. You may hard code the values into the method call which would look something like:
        Video video1 = new Video("123", "Sam Spade", 1454, 11204, 4.5, "mystery");
      
    Alternatively you may use the Scanner class to read the data in from keyboard.
  2. Call the toString method to print out the video information for all four videos.
  3. Determine the longest video and print out the length in seconds.
  4. Determine the smallest video and print out the size in KB.
  5. Determine if two videos that contain different data are equal.
  6. Determine if two videos that contain the same data are equal.
A sample output for the program could look like:
ID: 123 Author: Sam Spade Length: 24:14 Size: 10.964 MB Rating: 4.5 Tag: mystery
ID: 456 Author: Cam Comedy Length: 8:4 Size: 4.1007 MB Rating: 3.4 Tag: comedy
ID: 789 Author: Doni Dance Length: 12:25 Size: 7.888 MB Rating: 1.2 Tag: dance
ID: 789 Author: Doni Dance Length: 12:25 Size: 7.888 MB Rating: 1.2 Tag: dance
The longest video in seconds: 1454
The shortest video in KB: 8056
Video 1 equals video 2 is: false
Video 3 equals video 4 is: true

Work Incrementally!!!

  1. Create the Video class and the constructor.
  2. Create the toString method on the Video class.
  3. Create the VideoDriver class.
  4. Create the main method in the VideoDriver class.
  5. In the main method, create several instances of the Video class and call the toString method to display them.
  6. Incrementally create the rest of the methods in the Video class, modifying the VideoDriver class to test each method.
  7. And so on...
Test your code carefully to make sure that it operates correctly under a variety of test cases. Your code should have good programming style and follow all Java conventions. Don't forget to use constants where appropriate.

You're done!! Don't forget to log out and hand in your printouts to the professor before you leave!!