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 1Aguilar Jr, Jaime Barrett Wright, Matthew |
Team 2Amezcua Gutierrez, Edson Bloom, Thomas |
Team 3Baird II, Owen Cuddington, Christopher |
Team 4Berman, Jake Field, Sarah |
Team 5Coudriet, Blake Hansen, Mitchell |

Team 6Erickson, Joel Hastings, Jake |
Team 7Goeke, Maxwell Hogan, Martin |
Team 8Harris, Alexander Ling, Nathan |
Team 9Heflick, Elizabeth Nash, Christopher |
Team 10McCauley, Rylee Olivares, Scott |

Team 11Millard, Ryan Shearer, Stetson |
Team 12Olden, Gregory Wagster, Nathan |
Team 13Quayle, Weston Smith, Stephanie |
Team 14Straub-Walden, Andrew Akana, Christopher |
Team 15Williamson, 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.

- Partners sit side-by-side at one computer, sharing the keyboard, mouse, and monitor
- One team member (the
**driver**) has control of the keyboard/mouse and actively implements the program - The other team member (the
**navigator**) continuously observes the work of the driver to identify tactical defects (such as syntactic and spelling errors, etc.) and also thinks strategically about the direction of the work

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:

**Convert**the starting time in hours and minutes to the equivalent**total minutes**- For example:
`2`

hours and`30`

minutes would be`150`

total minutes - For example:
`5`

hours and`15`

minutes would be`315`

total minutes - Hint: use multiplication and addition

- For example:

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

**Add**the duration (in minutes) to this starting time (in total minutes), giving you the ending time in total minutes- For example: a start time of
`150`

(in total minutes) plus`125`

minutes duration duration gives you an ending time of`275`

total minutes - For example: a start time of
`315`

(in total minutes) plus`10`

minutes duration gives you an ending time of`325`

total minutes

- For example: a start 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

- Convert the ending time in total minutes back to hours and minutes with
`/`

and`%`

integer operators and the fact that one hour is**60**minutes- For example,
`63`

minutes is`1`

hour and`3`

minutes - For example,
`125`

minutes is`2`

hours and`5`

minutes - For example,
`325`

minutes is`5`

hours and`25`

minutes

- For example,

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

`EndingTime.java`

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

import java.util.Scanner;

public class EndingTime

{

public static void main(String [] args)

{

// Variable declarations

// Hint: All variables need to be declared as integers

// Create a Scanner object to read from the keyboard

Scanner keyboard = new Scanner(System.in);

// Get the starting time in hours and minutes

// Get the duration time in minutes

// Calculate the ending time

// Display the output

}

}

public class EndingTime

{

public static void main(String [] args)

{

// Variable declarations

// Hint: All variables need to be declared as integers

// Create a Scanner object to read from the keyboard

Scanner keyboard = new Scanner(System.in);

// Get the starting time in hours and minutes

// Get the duration time in minutes

// Calculate the ending time

// Display the output

}

}

**Sample Session**

Enter the starting time (in hours and minutes):`2 30`

Enter the duration (in minutes):`125`

Ending hour is 4 Ending minute is 35

**Copy and paste**the skeleton class code into`EndingTime.java`

to get you started- Type in your program code
**Compile**your program and correct all the syntax errors**Run**your program and compare your results to the test case values you hand calculated (in military hours)

**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).

- For example:
`13 30`

would be converted to`1 30`

`15 10`

would be converted to`3 10`

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 % |

- Modify your program using the formula given to produce ending times using
**standard time** **Compile**your program and find and correct all the compiler syntax errors identified by the compiler**Run**your program and compare your results to the test case values you hand calculated (regular hours)

- By showing up on time for lab, working collaboratively with your pair partner on the lab solution, and staying to the end of the class period, you receive full credit for the lab assignment.
**Copy**the contents of the`lab`

folder to the partner's USB thumb drive (or email it to them if they do not have a thumb drive).- Turn in the
**Lab assignment sheet**to your TA to receive credit for the lab- Include both partners' names and the test case tables and formulas filled out

- If you are
to attend Today's lab,*unable*- Print out the Lab 3 Assignment Sheet, write you name and account number on the sheet, and fill in the
**test case data**and formulas - Write the program on your own, individually, (
**not**using pair programming) - Run your program and confirm that your program's output matches the hand-calculated values on your Lab Assignment Sheet
- Save the work to your
`U:\labs\lab3`

folder and turn in the Lab 3 assignment sheet**at the start of the next lab**- Your grader will check your work in your CS 110 account

- Print out the Lab 3 Assignment Sheet, write you name and account number on the sheet, and fill in the

You are allowed to drop your lowest lab grade for the entire quarter.