CPSC-115 Fall 2008
Lab 3
September 16, 17 2008
Professor Heidi Ellis

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

Objective:

Postlab: The postlab for Lab 3 involves creating a document that answers the questions listed below. You should be thinking about these questions as you complete the lab. The postlab may be completed in pairs.
  1. What is the syntactic difference between calling methods on strings and calling methods on the Math class? Specifically list the elements of the Java language that are used when calling these two different types of methods.
  2. Explain the reason for the difference. You may want to look at the API documentation for these two classes.
  3. Some of the methods that you used to complete the lab had something between the open and closed parens while others did not. Explain the difference between having something and having nothing. This explanation should identify the general reason for the difference, and not be limited to a specific example.

Pair Programming:
  1. Locate your partner and introduce yourself:
  2. Tuesday Lab   Wednesday Lab
    Kristen AndersonJeff Young     Chelsea Bainbridge-DonnerJin Feng Liu
    Zain KahnNick Dragu     Greg VaughanCorazon Irizarry
    Jake Elder      Jesse VazquezJohn Wilsterman
           Ryan ErslandCatherine Doyle
  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.

VideoCalculator

The domain of our second program is the same as for Lab 2, that of YouTube videos. In this lab, you will use the Scanner class to input information on a video including the ID, author, name (note that this information has been added since Lab 2), length, size, rating and tag. In addition, you will use methods defined on the String and Math classes to carry out some calculations. However, in this case, you only need to represent information for two videos. Specifically, you must write a program to:
  1. Create a VideoCalculator class with a public static void main method. You may use the VideoCalculator class from Lab 2 as a starting point.
  2. Define all necessary variables. Don't forget to add a variable for the name of the video. Don't forget to remove variables defined for that third video if you are using the program from Lab 2 as a starting point.
  3. Declare a constant for the number of videos. Remove any extra constants that may be left over from Lab 2.
  4. Create an instance of the Scanner class.
  5. Prompt the user to enter information for two videos and use the instance of the Scanner class to store the input values into the variables.
  6. Display all video information.
  7. Use methods defined on the String class to calculate and display the following:
    1. The length of the name of the first video.
    2. The character at the fourth location in the tag of the first video.
    3. The first and last character in the tag of the second video.
    4. The index of the first occurrence of the character 't' in the name of the first video.
    5. Create and print a new string by replacing all of the 'a's with 'e's in the name of the first video.
    6. A substring of length three of the name of the first video starting at location two.
    7. The author of the first video in all uppercase.
  8. Use methods defined on the Math class to calculate and display the following:
    1. The length of the shorter video.
    2. The length of the longer video.
    3. The round of the rating of the first video.
    4. The average length of both videos in seconds.
    5. The floor of the average of both videos.
    6. The ceiling of the average of both videos.
  9. Use an if statement to print the information for the video that takes up the most space.
The display of your program should look something like the following:
Enter the ID of the video:123
Enter the author of the video:Sam Spade
Enter the name of the video:It was a dark and stormy night
Enter the length in seconds of the video:4567
Enter the size in MB of the video:82723
Enter the rating of the video (decimal between 1 and 5):4.3
Enter the tag for the video:noir mystery

SECOND VIDEO
Enter the ID of the video:456
Enter the author of the video:Dancin Dana
Enter the name of the video:Hip Hop Hype
Enter the length in seconds of the video:38909
Enter the size in MB of the video:832972
Enter the rating of the video (decimal between 1 and 5):5.0
Enter the tag for the video:hip hop dance

VIDEO INFORMATION
ID 1: 123 Author: Sam Spade Length: 4567 Size: 82723 Rating: 4.3 stars  Tag: noir mystery
ID 2: 456 Author: Dancin Dana Length: 38909 Size: 832972 Rating: 5.0 stars  Tag: hip hop dance

Length of name of first video: 30
Character at the fourth location in the tag of first video:  
First video tag, first character: n last character of tag: y
Location of the first occurrence of the character 't' in the name of the first video:1
Replacing the 'a's with 'e's in first video name: It wes e derk end stormy night
Substring of length two starting at location three of first video name: wa
Upper case name of author of first video:SAM SPADE

The minimum length of the two videos is: 4567
The maximum length of the two videos is: 38909
Rounding the rating of the first video: 4
Average length of both videos: 21738.0
Floor of the average: 21738.0
Ceiling of the average: 21738.0

Smallest video: ID 2: 456 Author: Dancin Dana Length: 38909 Size: 832972 Rating: 5.0 stars  Tag: hip hop dance

Hints:

If you have time...

Go back to lab 2 and complete Program 2. Use the Scanner class to input data.

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