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...

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. Implement a Door class as described below as well as a TestDoor class 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 object can • display an inscription, • be either open or closed, and • be either locked or unlocked. Here are some rules about how Door’s 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 writing 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 a 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.
Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here