Problem

Suppose that you are scheduling a room. You are given a group of activities each of which...

Suppose that you are scheduling a room. You are given a group of activities each of which has a start time and stop time. Two activities are compatible if they do not overlap. For example, in the following activities, activity A is compatible with activities B and D, but not activity C:

Activity

Start Time

Stop Time

A

1

2

B

2

5

C

1

3

D

5

6

Your goal is to schedule compatible activities that result in a maximum usage of the room.

a. Design a recursive algorithm to solve this room-scheduling problem. The method whose signature is

maxRoomUse(int startTime, int stopTime, Activity[] activities)

returns a pair consisting of the maximum usage in hours and an array of activities scheduled. Note that startTime is the first time that an activity can be scheduled, stopTime is the final time, and activities is an array of possible activities.


b. Write the class Activity and a class Schedule that represents the pair that maxRoomUse returns. Then write a program that defines the method maxRoomUse. The program should read the start time and stop time for the room followed by the start and stop times for each activity (one activity per line). After displaying the given activities, display the maximum usage in hours of the room along with a list of the scheduled activities.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 7
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT