Learning Objectives
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:
| Team 1 Aguilar Jr, Jaime Barrett Wright, Matthew |
Team 2 Amezcua Gutierrez, Edson Bloom, Thomas |
Team 3 Baird II, Owen Cuddington, Christopher |
Team 4 Berman, Jake Field, Sarah |
Team 5 Coudriet, Blake Hansen, Mitchell |
| Team 6 Erickson, Joel Hastings, Jake |
Team 7 Goeke, Maxwell Hogan, Martin |
Team 8 Harris, Alexander Ling, Nathan |
Team 9 Heflick, Elizabeth Nash, Christopher |
Team 10 McCauley, Rylee Olivares, Scott |
| Team 11 Millard, Ryan Shearer, Stetson |
Team 12 Olden, Gregory Wagster, Nathan |
Team 13 Quayle, Weston Smith, Stephanie |
Team 14 Straub-Walden, Andrew Akana, Christopher |
Team 15 Williamson, Sarah Millard, Mikel |
| 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 4 35
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 (in minutes) | Ending Hour (military time 0..23) | Ending Minute (0..59) |
|---|---|---|---|---|
| 1 | 30 | 120 | ||
| 11 | 45 | 60 | ||
| 12 | 40 | 90 | ||
| 10 | 0 | 240 |
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:
2 hours and 30 minutes would be 150 total minutes5 hours and 15 minutes would be 315 total minutesOn 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 125 minutes duration duration gives you an ending time of 275 total minutes315 (in total minutes) plus 10 minutes duration gives you an ending time of 325 total minutesOn 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
/ and % integer operators and the fact that one hour is 60 minutes
63 minutes is 1 hour and 3 minutes125 minutes is 2 hours and 5 minutes325 minutes is 5 hours and 25 minutesOn 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
EndingTime.javaUse 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
Sample Session
Enter the starting time (in hours and minutes):2 30Enter the duration (in minutes):125Ending hour is 4 Ending minute is 35
EndingTime.java to get you startedChange 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 30 would be converted to 1 3015 10 would be converted to 3 10Doing 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 % |
lab folder to the partner's USB thumb drive (or email it to them if they do not have a thumb drive).U:\labs\lab3 folder 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.