After completion of this lab, you should be able to
All labs in CS 110 will be done as pair programming teams. Your partner for today's lab is listed in the table below:
Aguilar Jr, Jaime
Barrett Wright, Matthew
Amezcua Gutierrez, Edson
Baird II, Owen
|Fill in: Awan, Samara|
Note: Partners will change every week.
You may wish to review basic pair programming guidelines before you begin.
You should change roles every 10 to 15 minutes.
Write a Java program that can serve as a ending time calculator. The user enters the starting time in hours and minutes, a duration in total minutes, and your program will calculate and display the ending time (as hours:minutes).
For example, if an event starts at
2 30 and lasts
125 minutes, it will end at
Note: To simplify the problem, assume military time (0..23) rather than standard time, in which you would need to worry about a.m. and p.m.
Begin by developing test cases for this program. Ending time should be expressed in military time (0..23)
For example: 1:30 p.m. is expressed as 13:30 military time
|Start Hours||Start Minutes||Duration |
(military time 0..23)
|Ending Minute |
Write your calculated test case values on the Lab 3 assignment sheet. You will turn in this sheet at the end of lab for credit.
The algorithm to solve this problem on a computer is not straight-forward. Here is a solution:
30minutes would be
15minutes would be
On the Lab 3 assignment sheet, write down the math formula needed to calculate the starting time (in total minutes) given the start hours and start minutes.
startingTime (in total minutes) = write out the formula
150(in total minutes) plus
125minutes duration duration gives you an ending time of
315(in total minutes) plus
10minutes duration gives you an ending time of
On the Lab 3 assignment sheet, write down the math formula needed to calculate the ending time (in total minutes) given the starting time (in total minutes) and the duration (in minutes).
endingTime (in total minutes) = write out the formula
%integer operators and the fact that one hour is 60 minutes
On the Lab 3 assignment sheet, write down the math formula needed to calculate the ending hour and minutes given the ending time (in total minutes).
Note: at this point, assume simple military time for the end hours. So 12:50 plus 30 minutes would be 13:20
endingHour = write out the formula
endingMinutes = write out the formula
Use jGRASP to write the Java program
EndingTime.java that calculates the ending time (in hours and minutes), given a starting time (in hours and minutes) and a duration (in minutes).
The skeleton class code for
EndingTime is provided below
Enter the starting time (in hours and minutes):
2 30Enter the duration (in minutes):
125Ending hour is 4 Ending minute is 35
EndingTime.javato get you started
Change pair partner roles. The driver should become the navigator, the navigator should become the driver.
Modify your program so that it converts the hours in military time (0..23) to hours in standard time (1..12).
13 30would be converted to
15 10would be converted to
Doing the modulus 12 conversion is not as straightforward as it may at first seem. Dividing by 12 will always returns a remainder value between 0 .. 11. Standard time hours are expressed as 1 .. 12.
A formula to perform the conversion is
|where h is military time hours and mod is the modulus operator %|
labfolder to the partner's USB thumb drive (or email it to them if they do not have a thumb drive).
U:\labs\lab3folder and turn in the Lab 3 assignment sheet at the start of the next lab
You are allowed to drop your lowest lab grade for the entire quarter.