Question: What would the JAVA application example look like to compile...? Homework 5: Adventure Game-Object Oriented Approach Description: In this assignment we will use an object-oriented

What would the JAVA application example look like to compile...?

Homework 5: Adventure Game-Object Oriented Approach Description: In this assignment we will use an object-oriented approach to implement your dungeon. Required Concepts: Modeling with objects Instance Variables Getters and Setters Constructors Instance methods Composition (has-a) Modeling 

Homework 5: Adventure Game-Object Oriented Approach Description: In this assignment we will use an object-oriented approach to implement your dungeon. Required Concepts: Modeling with objects Instance Variables Getters and Setters Constructors Instance methods Composition (has-a) Modeling the Adventure Game using Objects: The first step to refactoring your adventure game is to identify the objects that are required to build your game. A good rule of thumb is that you should divide the application's responsibilities into objects. You should use UML diagrams to determine the objects' properties and behaviors. In your adventure game the user explores a dungeon, which consists of a series of interconnected rooms. So, you must define a class that represents a room object and a dungeon object. Room description: String north: Room east: Room west: Room south: Room < > Room (description: String) + setNorth (north: Room) + setEast (east: Room) + setWest (west: Room) + setSouth (south: Room) + setExits (n: Room, e: Room, w: Room, s: Room) + getNorth(): Room + getEast (): Room + getWest(): Room + getSouth(): Room + getDescription(): String Room +getExits(): String + toString(): String UML class diagram for Room -East Lobby: -East Veranda: -Gallery: -Guest Boudoir: -Library: -Master Boudoir: -North Lobby: -North Veranda: -South Lobby: -South Veranda: -Theater Room: -West Lobby: -West Veranda: < > Dungeon() + getRoom0(): Room Dungeon UML class diagram for Dungeon Dungeon has-a 1...* Room Composition Both Dungeon and room use composition since they have a has-a relationship to room. It's important to understand that an object can hold a reference to its own type so a room can have references to the other rooms that connect to it. The ability to link objects directly to one another is a critical aspect in understanding data structures. Below is UML relationship diagram showing the relationships that our two classes have with one another. Room Room Room Room Room Room Room Room Room Room Room Room Room 4 has-a Room Class Rooms are responsible for representing an area in the dungeon. The properties that define a room are its description and its exits. The room description may be stored using a String. For the exits, this room can hold references to other rooms that connect to it. The room constructor only sets up its description leaving its exits initially null. Client code can then update the room's properties with getter and setter methods. It would be convenient to also have a method that can set all 4 exits at once. The room's description shouldn't say its exits; instead have a method (getExits) that creates a String of exits. The toString method should contain the description and the exits. Dungeon Class The dungeon is responsible for setting up all the rooms and establishing the connections between them. The dungeon's properties (i.e. instance variables) are the rooms that it contains. The dungeon constructor should initialize all of the rooms' descriptions and its exits. The only method that our dungeon needs is to provide the starting room. Once we have the starting room we can navigate to any other room from using the rooms themselves. UML Class relationship Diagram Dungeon has 1 or more instance of class Room. Room has exactly 4 instances of class Room, one for each direction.

Step by Step Solution

3.65 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The Java application example to compile would look like this Java import javautilScanner public class AdventureGame public static void mainString args Scanner scanner new ScannerSystemin Create a dung... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!