Question: A Door Class A computer game usually has many different objects that can be seen and manipulated. One typical object is a door. Whether a
A Door Class A computer game usually has many different objects that can be seen and manipulated. One typical object is a door. Whether a player runs through a castle, attacks the forces of an evil empire, or places furniture in a room, a door often comes into play( not for Jupitrian). Implement a Door class and describe below as well as a TestDoor that instantiates three Door objects labeled Enter,Exit, and Treasure. The Enter door should be left unlocked and opened. The Exit door should be left closed and locked. The Treasure door should be left open but locked. A Door class A Door class can: Display an inscription Be either open or closed, and Be either locked or unlocked. Here are some rules about how Doors work: Once the writing on a Door is set, it cannot be changed You may open a Door if and only if it is unlocked and closed You may close a Door if and only if it is open You may lock a Door if and only if it is unlocked, and unlock a Door if and only if it is locked. You should be able to check whether or not a Door is closed, check whether or not it is locked, and look at the writhing on the Door if there is any. The instance variables of a Door class are: String inscription Boolean locked, and Boolean closed. The methods (all public) should be: Door(String c); // Constructor initializes a Door with inscription c , closed and locked isClosed(); // Returns true if the Door is closed isLocked(); // Returns true if the Door is locked open(); // Opens a Door if it is closed and unlocked close(); // Closes a Door if it is open lock(); // Locks a Door if it is unlocked unlock(); // Unlocks a Door if it is locked Appropriate error messages should be displayed, if any conditions of the methods are violated.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
