CPSC-115 Fall 2008
Lab 2
September 9,10 2008
Professor Heidi Ellis
Be sure that you hand in the printouts of your work before leaving!!!
Objective:
- To become familiar with data types, assignment statements, operators and operator precedence.
Prelab: The prelab for Lab 2 involves creating a document containing the following:
- Program 1:
- A definition of the variables and types needed to represent all information for the VideoCalculator program (see below). Think carefully about the variables that you will need and the types of the values that the variables should hold.
- Identify the operators that must be used in order to calculate the length of each video in minutes and seconds. Remember that the length of each video is stored in seconds only.
- Write the algorithm to calculate and print the average MB of video that is used per minute of playing time. Remember that the length of each video is stored in seconds. You may use either outline or flowchart notation.
- Program 2:
- A definition of the variables and types needed to represent all information for the GinaSchedule program (see below). Think carefully about the variables that you will need and the types of the values that the variables should hold.
- Review the functions provided by the Math class and identify the function that should be used to return the smaller of two numbers. The function should take values of the type that agree with the variables that you have defined in the previous step.
Hand in a hard copy (must be neat!!!) at the beginning of lab.
Pair Programming:
- Locate your partner and introduce yourself:
| Tuesday Lab |
|
Wednesday Lab |
| Kristen Anderson | Nick Dragu |
|
Chelsea Bainbridge-Donner | Corazon Irizarry |
| Zain Kahn | Ben Hartung |
|
Greg Vaughan | John Wilsterman |
| Jake Elder | Jeff Young |
|
Jesse Vazquez | Catherine Doyle |
| | |
|
Ryan Ersland | Jin Feng Liu |
- Select one person to start as "driver". This person will type at the keyboard for the first 20 mintues.
- Proceed through the process of completing the lab as described below. Be very careful to ensure that every item for both programs is completed.
- Swap pairs every 20 minutes.
- 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.
Program 1: VideoCalculator
The domain of the first program is that of YouTube videos. In this lab, you will use a subset of the information typically used to describe a YouTube video. You will use information for three videos and will also perform some calculations on that information. The information that you need to represent for each video are the id of the video, the author, the length of the video in seconds, the size of the video in MB, the rating for the video, (a value between one and five which could have a decimal), and a tag for the video (brief description of the cateogry of the video). You must write a program to:
- Create a VideoCalculator class with a public static void main method.
- Define all necessary variables.
- Declare constants for the number of videos, number of seconds in a minute (60) and number of MB in a GB (1024).
- Initialize all video information to values of videos.
- Display all video information.
- Calculate and display the following:
- The length of each video in minutes and seconds. Print the ID of each video followed by its length in minutes and seconds.
- The total length of all three vidoes in seconds.
- The average length of all three videos in seconds.
- The average length of all three videos in minutes and seconds.
- The total space taken up by all three videos in MB.
- The total size of all three videos in GB and MB.
- The average size of all three videos in MB.
- The average number of MB of video that is used per minute of playing time.
The display of your program should look something like the following:
VIDEO INFORMATION
ID 1: 123 Author: Sam Spade Length: 1454 Size: 1204 Rating: 4.5 stars Tag: mystery
ID 2: 456 Author: Cam Comedy Length: 484 Size: 503 Rating: 3.4 stars Tag: humor
ID 3: 789 Author: Doni Dance Length: 745 Size: 856 Rating: 1.2 stars Tag: dance
VIDEO LENGTH
123 Length: 24:14
456 Length: 8:4
789 Length: 12:25
CALCULATIONS
Total length of all videos: 2683.0 seconds.
Average video length: 894.3333333333334 seconds
Average video length: 14 minutes and 54 seconds
Total size of all videos: 2563.0 MB
Total size of all videos: 2 GB and 515 MB
Average video size: 854.3333333333334 MB
Average MB per minute: 57
Program 2: GinaSchedule
The domain for the second program is that of military time. Remember that military time uses a 24 hour representation rather than the 12 hour a.m./p.m. representation. For example, 3:00 p.m. is 15:00 in military time. We will only be looking at the hours portion of the time.
General Gina is trying to schedule and coordinate various activites (e.g., marches, training sessions, etc.) and needs to know what time it will be at various points in the future. You must write a program to satisfy General Gina's questions. You must:
- Create an GinaSchedule class with a public static void main method.
- Declare variables to hold military time and to hold an alternate time. (In step 7 below General Gina will want to compare two times.) You may also need additional variables.
- Declare a constant to hold the number of hours in a day (24).
- General Gina wants her schedule to start tomorrow at 12:00 a.m. so initialize the military time variable to zero hours and display the time.
- General Gina's first item to be scheduled is a surprise barracks inspection. This will take two hours. Use the increment (++) operator to add one hour to the time two times and redisplay the time.
- General Gina's second item to be scheduled is a prolonged march taking 36 hours. Use the += operator to add 36 hours to the time. Use the modulo operator to modify the time to the correct military time and display the results.
- General Gina wants to compare the time of day of the previous schedule (surprise barracks inspection followed by the prolonged march) with a schedule that contains a rest period of 5 hours followed by a troop move taking 29 hours. Calculate the second time and print.
- Use the appropriate function defined on the Math class provided by Java to calculate the earlier of the two times. Display the earlier of the two times.
Your output should look something like the following:
Starting time: 0:00
Time after surprise barracks check: 2:00
Time after prolonged march: 14:00
Time after rest followed by troop movement: 10:00
Earlier time: 14:00
You're done!! Don't forget to log out and hand in your printouts to the professor before you leave!!