CS 116 Spring 2020 Lab #1: Due: Sunday, February 2nd, Midnight Points: 20
CS 116 Spring 2020 Lab #1: Due: Sunday, February 2nd, Midnight Points: 20
Elizabeth Aquino
Instructions:
1. Use this document template to report your answers. Enter all lab partner names
at the top of first page.
2. You don’t need to finish your lab work during the corresponding lab session.
3. Name the complete document as follows:
LastName_FirstName_CS116_Lab1_Report.doc
4. Submit the final document to Blackboard Assignments section before the due
date. No late submissions will be accepted.
5. ALL lab partners need to submit a report, even if it is the same document.
Objectives:
1. (12 points) Design a class for an everyday object, including required data and
methods.
2. (8 points) Use arithmetic operators. Understand and apply precedence of
operations. Understand and apply explicit casting. Use methods of the Java
predefined String classes.
1
Define the private attributes (and their data types and valid ranges) and public
methods (and their arguments and return types) for the following classes. You do
not need to code, just design.
Populate provided tables (enter as many rows as you find necessary; add more if
needed) with your answers. Feel free to add extra tables, boxes, comments, etc. if
needed.
2
2. A fraction data type [4 points].
3
cashStored Float 0-1000 Amount of cash in machine
Problem 2 [8 points]:
Use arithmetic operators. Understand and apply explicit casting. Use methods of the
java predefined String classes.
Marathon times are usually recorded in hours, minutes and seconds. Also, marathon
runners like to compare their time with the world record holder's time and see what
percentage slower they are than the world record time. To make the comparison
easier and to calculate the percentage slower, it helps to convert into seconds both a
person's time (entered as three integers: hours, minutes and seconds) and the world
record holder's time (2 hours, 3 minutes and 59 seconds). It is OK to display the
percentage in its decimal form.
4
//Lab 1 due 2/2/2020
// add expression to convert the record hours and minutes and seconds to
seconds;
public Runner (String n, int h, int m, int s){
name = n;
setTime(h, m, s);
}
5
add two methods to this class:
"percentageSlower", and
a second constructor that takes two String arguments, name and data, and
parses the second colon-delimited String into integer hours, minutes,
seconds.
Now:
Write pseudocode (place it in the box below) for solving the problem of
calculating the above described marathon statistic,
Pseudocode:
Method setTime:
public void setTime (h,m, s){
if (h>=0 && m>=0 && s>=0)
6
marathonTimeSeconds =(h*60*60)+(m*60)+s;
}
Method: percentageSlower
public double percentageSlower (){
double per = 0
per =Math.abs(worldRecordTime);
double error = per/ worldRecordTime *100;
return error;
}
Test plan
Test case Sample data Expected result Verified?
World record in Bikila Time in seconds: 8116 Yes
1960 Percentage slower: 9.10
Name: Bikila
Bikila
Hours: 2
2
Minutes: 15
15
Seconds: 16
16
7
Current women's Radcliffe Time in seconds: Yes
record 8125 Percentage slower:
9.22
Name: Radcliffe
Radcliffe
Hours: 2
2
Minutes: 15
15
Seconds: 25
25
My friend's time Gomez Gomez Time in seconds: Yes
16194 Percentage slower:
Name: Gomez 4 117.69054980508133
Hours: 4 29
Minutes: 29 54
Seconds: 54
Your own Cordell Cordell Time in seconds: Yes
16200 Percentage slower:
marathon time
4 117.77120580723215
(or estimate)
30
Name:
00
Hours:
Minutes:
Seconds: