Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Java A computer game usually has many different objects that can be seen and manipulated. One typical object is a door Whether a player
In Java 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. Each door has an inscription (such as "Enter"Exit", .. Treasure, etc.) and can be 1n the ''Open" or "Closed state, and "Locked" or "Unlocked" state The objective of this question is to implement a Door class that has the following: String inscription boolean locked boolean closed and the following methods Constructor that instantiates a Door with a given inscription, closed and locked. isClosed returns true if the Door is closed isL sked 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 (but does not lock it) lock locks a Door if it is unlocked unlock unlocks a Door if it is locked (but does not open it). toStung displays the inscription and whether the Door that is locked/unlocked, closed/open. Add any other methods as necessary. Display appropriate error messages if any conditions of the methods are violated. Next write a TestDoer class (with a main method) as follows In the TestDoor class, use another boolean variable called key. If the key is true, then a Door can be unlocked. If the key is false, the Door cannot be unlocked. When a door object is instantiated, it is initially in the locked and closed state Using random number generation, generate a Door object (Enter, Exit or Treasure - you can use 0, 1, and 2, respectively) and a key value (true/false - you can use 0 or 1). Change the status of the Door according to the following table. Repeat by placing the code in a loop. Each time the loop is entered, a new Door object and a new key value are randomly generated. ruc rue rue False False False oor Enter Exit Treasure Enter Exit Treasure Change status to Unlock and Unlock and Unlock and No change No change No change Your program should keep prompting the user (Play (Y or N)) and keep looping until the user enters N Note: A player cannot "Exit" without having gone through the "Enter" door. Similarly, a player cannot get to the Treasure" door without having gone through the "Enter" door. A player who has gone through "Exit" must again go through the "Enter" door. If these conditions are not met, then the output must display a message accordingly Here's a sample run of the program (assuming some arbitrarily generated door and key values) Welcome to the Dungeon. Play? (Enter Y or N):Y Door: Exit Key: True Sorry. Cannot exit without entering Play? (Enter Y or N) Y Door: Treasure Key: False Sorry. Cannot get to Treasure without entering
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started