Question 2: Class Design
Overlapping time slots
- Units 2 and 3
- 7 points
- About 25 minutes
You write a whole class from a description and a table of example calls and results: the class header, private instance variables, a constructor and the required method. New since the course was revised for 2025–26 (first tested in May 2026): it's worth 7 points instead of 9, and points are no longer taken off as penalties. On the exam: Question 2 of 4, 7 points. Section II has 4 free-response questions in 90 minutes (45% of the score), all assessing Practice 2 (Develop Code). The exam is fully digital in Bluebook: you type your Java, and the Java Quick Reference is provided. No calculator. Suggested time is our split of the 90 minutes by points; College Board gives no per-question timing.
The question and its sources
The TimeSlot class, which you will write, represents a block of time in a school's room-booking system. Times are whole numbers of minutes after midnight, so 540 means 9:00 a.m.
A TimeSlot object is created with two int parameters: the start time and the end time. Assume the start time is less than the end time. The slot includes every minute from the start time up to, but not including, the end time.
The class has four methods.
- getStart and getEnd have no parameters and return the start and end times.
- overlaps has a TimeSlot parameter and returns true if this slot and the other slot share at least one minute, and false otherwise. A slot that ends at the exact time another starts does not overlap it.
- combine has a TimeSlot parameter. Assume the two slots overlap. It returns a new TimeSlot that starts at the earlier of the two start times and ends at the later of the two end times. Neither original slot is changed.
The table shows a sample sequence of statements and their results. The statements are in a class other than TimeSlot.
Sample statements and results
| Statement | Value returned (— if none) | Explanation |
|---|---|---|
TimeSlot a = new TimeSlot(540, 600); | — | 9:00 to 10:00 |
TimeSlot b = new TimeSlot(570, 630); | — | 9:30 to 10:30 |
TimeSlot c = new TimeSlot(600, 660); | — | 10:00 to 11:00 |
a.overlaps(b) | true | Minutes 570 to 599 are in both. |
a.overlaps(c) | false | a ends at 600, exactly when c starts. |
b.overlaps(c) | true | Minutes 600 to 629 are in both. |
TimeSlot d = a.combine(b); | — | A new slot from 540 to 630. |
d.getStart() | 540 | The earlier start. |
d.getEnd() | 630 | The later end. |
a.getEnd() | 600 | a is unchanged. |
Source: Hypothetical example
Suggested time: 25 minutes
Your answers are saved in this browser as you type.
Part (a)
7 pointsWrite the complete TimeSlot class. Your implementation must meet all specifications and conform to the examples shown in the table.
Tab indents. Press Esc, then Tab, to move on.
0 lines · 0 / 2,500 characters
Checking scoring…
Scoring it yourself shows you the rubric, examples and a model answer. Try writing your answer first.