Question
Need to be answered correctly. You must: Comment and Format and Must make sure about indenting. If you don't follow these steps, it will be
Need to be answered correctly. You must: Comment and Format and Must make sure about indenting. If you don't follow these steps, it will be flagged for review. MUST BE IN JAVA FORMAT. IT IS A MUST. Please also check the output very carefully. Must not provide the answer on a page. Use the Java compiler. Please provide the code in such a way so that it can be copied and checked in the Java compiler. Must provide the coding as (.......).java and (........)Demo.java (Public class must be based on the question for both Door.java and DoorDemo.java )
Need to be answered correctly. You must: Comment and Format and Must make sure about indenting. If you don't follow these steps, it will be flagged for review. MUST BE IN JAVA FORMAT. IT IS A MUST. Please also check the output very carefully. Must not provide the answer on a page. Use the Java compiler. Please provide the code in such a way so that it can be copied and checked in the Java compiler. Must provide the coding as (.......).java and (........)Demo.java (Public class must be based on the question for both Door.java and DoorDemo.java )
Exercise 1 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 in 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 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 (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). toString displays the inscription and whether the Door that is locked/unlocked, closed/open. . as necessary. Display appropriate error messages if any conditions of the methods are Add any other methods violated. Next write a TestDoor 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. Ke True True True False False False Door Enter Exit Treasure Change status to Unlock and o Unlock and o Unlock and o No change No change No change Exit Treasure 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 accordinglyStep 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