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:
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:
Kristen Anderson Greg Vaughan
Jake Elder Ryan Ersland
Jin Feng Liu John Wilsterman
Catherine Doyle Jeffrey Young
Nick Dragu Jesse Vasquez
Chelsea Bainbridge-Donner Corazon Irizarry
| 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 |
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: mysteryYou must create a VideoDriver class. The only thing that the VideoDriver class contains is a main method. Your main method should:
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.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