Consider the problem of trying to do a number of loads of laundry, given only one washer and one dryer. Washing a load takes 25 minutes, drying a load takes 25 minutes, and folding the clothes in a load takes 10 minutes, for a total of 1 hour per load (assuming that the time to transfer a load is built into the timings given). All the laundry can be done in 10 hours, 600 minutes, using the method of completing one load before starting the next one.
Write the method, minutesNeeded, that returns the shortest time needed to do m loads of laundry. In other words, given an
integer value representing the number of loads to complete, m, determine the smallest number of minutes
needed to complete all loads of laundry.
int
int
public int minutesNeeded (int m)
m is a positive number less than 1000
(i.e., 0 < m < 1000).
1
Returns: 60
You must wash the laundry, 25 minutes, dry the laundry, 25 more minutes, and fold the laundry, 10 more minutes; for a total of 60 minutes.
2
Returns: 85
You wash the first load of laundry, then dry it, and fold it. While it is drying, you start washing the second load of laundry. When it finishes, the first load is done drying, so you can start drying the second load. You can fold the first load while the second load is drying, but you need ten extra minutes to fold the last load.
3
Returns: 110
You wash the first load of laundry, then dry it, and fold it. While it is drying, you start washing the second load of laundry. When it finishes, the first load is done drying, so you can start drying the second load. Since the washer is free again, you can start the last load. When the second load finishes drying, the last load is finished washing so you can start it drying. You can fold the first two loads while the third load is drying, but you need ten extra minutes to fold the last load.
12
Returns: 335