Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
6th Edition
ISBN: 9780134477367
Author: David J. Barnes, Michael Kolling
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 8, Problem 20E
Program Plan Intro

Program plan:

The variables used in the program are given below:

  1. item: An instance variable of type Item that represents the item in the room.
  2. hasItem: A boolean variable that is true if the room has an item and false otherwise.

The methods used in the program are as follows:

  1. Room(String description): A constructor method that takes a String parameter representing the description of the room, creates a new instance of the Room class, and initializes the instance variables.
  2. addItem(Item item): A method that takes an Item object as a parameter and adds it to the room if there is no existing item in the room.
  3. removeItem(): A method that removes the item from the room if there is one and returns it. If there is no item, it returns null.
  4. hasItem(): A method that returns true if the room has an item and false otherwise.
  5. getItemDescription(): A method that returns a String description of the item in the room or "none" if there is no item.
  6. getDescription(): An overridden method from the Entity class that returns the description of the room along with the description of the item, if there is one.

Program Description:

To extend the project so that a room can contain a single item.

Blurred answer
Students have asked these similar questions
What happens when you make a new map entry using a key that already exists on the map and click on it?
Picture card: Create a picture card that looks SIMILAR to this. There are images available in the "images" directory to assist you in making this card. They are not the same images, but there is an image of a desert and a person. Picture card In this screenshot, the title is "Title goes here", the secondary text is "Secondary text", and the body text is "Greyhound divisively hello coldly wonderfully marginally far upon excluding." The card's root element is a with a class of "card". The card is 344px wide. The desert picture is 194px tall. The padding between the body text and everything else is 16px. The color of the title text is #000. The color of the secondary and body texts is #232F34. The size of the person picture is 40px in diameter. The size of the body text is 11px. The size of the title is 22px. For the padding or margin around any other elements, use your best judgment to make it look like the screenshot.
when coding a chess game, implement the following method: isInCheck(Side s): Returns true if the king of side s is attacked by any of the opponent’s pieces, i.e., if in the current board state, any of the opponents pieces can move to where the king is. Otherwise, it returns false. Note that this method is only used to warn the player when they are in check. You can use the GUI to test if this is working.         public boolean isInCheck(Side side) {         // TODO write this method         return false;     }         public enum Side {     BLACK, WHITE;       public static Side negate(Side s) {         return s == Side.BLACK ? Side.WHITE : Side.BLACK;     } }
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT