Loading...
Loading...
Next semester's course starts as a copy of this one: the same code, the same teacher and the same weekly hours. The hours belong to each course, but the teacher is one real person, so a phone number update must reach both courses. Write the Course copy constructor, deciding each field, then run the changes.
CODE newCode or HOURS week h (both for next semester), or PHONE number (the teacher's new phone).This semester: <code> by <teacher> (<phone>) hours <hours> and the same line for Next semester:.Example
Input
CS201 Rao 9845011111 3 3 3 4 3 CODE CS201N HOURS 3 2 PHONE 9845022222
Output
This semester: CS201 by Rao (9845022222) hours 3 3 4 Next semester: CS201N by Rao (9845022222) hours 3 3 2
The hours change only next semester; the new phone shows in both.
Try the problem first. Open one hint at a time.
Ask for each field: does next semester own it, or point to the same real thing?
Clone the hours array; keep the teacher reference with plain =; String code needs no copy.
Apply PHONE to this semester's teacher: if the teacher is shared, next semester sees it too.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor