View the TrainCompartment
class. Your task is to properly apply encapsulation to this class. Make sure that:
enter()
by which one new passenger enters the train. This is only allowed when there are still seats available. If there are no more seats available this will be printed out.leave()
with which one passenger leaves the train. So now another seat becomes available. If no-one is left to leave, print a message.For your benefit, we added a class diagram to visualise this exercise.
Make an instance of the TrainCompartment
in the Application
class and test if your implementation works correctly. Also test the situations that can go wrong.
In case the train is empty: