Loading...
Loading...
A college hires teachers and assigns each to one department. A teacher can move to another department; the teacher object itself is never destroyed or copied.
Write Teacher and Department (a Teacher[5] array and a count) with add(Teacher t), Teacher remove(String name) (returns the removed teacher or null) and String show(). remove shifts the later teachers left.
hire NAME DEPT, move NAME FROM TO or show DEPT.HIRED NAME TO DEPT or DEPT FULL; MOVED NAME FROM TO, NAME NOT IN FROM or TO FULL; DEPT: N1 N2 … or DEPT: -.Example
Input
2 CSE ECE 6 hire Ravi CSE hire Meena CSE hire Anil ECE move Ravi CSE ECE show CSE show ECE
Output
HIRED Ravi TO CSE HIRED Meena TO CSE HIRED Anil TO ECE MOVED Ravi CSE ECE CSE: Meena ECE: Anil Ravi
Ravi leaves CSE and joins the end of ECE; Meena shifts to the front.
Try the problem first. Open one hint at a time.
Create a Teacher in main on hire, then add it: departments never call new Teacher.
For move, find the teacher in FROM first, then check that TO has room, and only then remove and add.
After shifting left, set the last filled place to null and decrease count.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor