Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

logo Practice-It logo

meetings

Language/Type: Java method basics Random return
Author: Marty Stepp (on 2011/01/05)

Write a method named meetings that schedules meetings of varying random lengths, starting from a given time, until a point in time where a meeting ends within 5 minutes of an hour mark. Your method should accept two parameters representing the starting hour and starting minute. The method should repeatedly produce random meeting lengths between 15 and 30 minutes inclusive, printing what the time would be after that meeting is over. You should stop when a meeting ends during the first or last 5 minutes of a given hour, that is, if the minutes hand of the clock is on 5 or less or 55 or higher. At least one meeting should always be scheduled regardless of the start time.

The following table shows three example calls to your method and their resulting output. To simplify the output in cases with minutes < 10, we'll print times in a format such as "2h 17m" instead of the more familiar "2:17".

Call meetings(2, 17); meetings(10, 14); meetings(7, 3);
Output
2h 17m start time
2h 40m after 23-min meeting
3h 7m after 27-min meeting
3h 36m after 29-min meeting
3h 51m after 15-min meeting
4h 9m after 18-min meeting
4h 33m after 24-min meeting
5h 0m after 27-min meeting
10h 14m start time
10h 39m after 25-min meeting
10h 54m after 15-min meeting
11h 12m after 18-min meeting
11h 30m after 18-min meeting
11h 47m after 17-min meeting
12h 6m after 19-min meeting
12h 22m after 16-min meeting
12h 41m after 19-min meeting
1h 9m after 28-min meeting
1h 35m after 26-min meeting
2h 5m after 30-min meeting
7h 3m start time
7h 18m after 15-min meeting
7h 38m after 20-min meeting
7h 57m after 19-min meeting

Note that a meeting can cause the current time to wrap into the next hour, and that the next hour after 12 is 1. Do not worry about AM vs. PM time for this problem. You may assume the parameter values passed will be legal values (starting hour between 1 and 12, starting minute between 0 and 59).

(Because this problem uses random numbers, our test cases check only the general format of your output. You must still examine the output yourself to make sure the answer is correct.)

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.