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?
Gradient FillIn this labwork are asked to write a GUI application again using AWT. This is a fairly easy labworkthat is more about getting used to synchronized online learning. You are expected to:• Draw two rectangles.• Both of them should be filled using GradientPaint() function of AWT. (Check out itsfunction definition that is listed below.)• The first gradient should be parallel to the diagonal of the first rectangle. The colorgradient should not be repeated (acyclic).• The second gradient should be horizontal. The color gradient should be repeated forthis one (cyclic).• You are free to choose the colors but other than that your output should be similar tothe example screenshot given below.
Scenario You work for a small company that creates text-based games. You have been asked to pitch an idea to your team for a text-based adventure game with a theme and environment of your choice. Your game must include different rooms, items, and a villain. The basic gameplay will require the player to move between different rooms to gather all of the items. A player wins the game by collecting all the items before encountering the villain. The player will have two options for commands in the game: moving to a different room, and getting an item from the room they are in. Movement between rooms happens in four simple directions: North, South, East, and West. You must include the designs for your game as a part of your idea pitch. Specifically, you have been asked to provide a map that displays the different rooms and items. You have also been asked to use pseudocode or flowcharts to design code for moving between rooms and getting items. If your pitch gets approved, these designs will…
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