What would the JAVA application example look like to compile...? Homework 5: Adventure Game-Object Oriented Approach Description:
Fantastic news! We've Found the answer you've been seeking!
Question:
What would the JAVA application example look like to compile...?
Transcribed Image Text:
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 <<Constructor>> 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: <<Constructor>> 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. 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 <<Constructor>> 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: <<Constructor>> 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.
Expert Answer:
Answer rating: 100% (QA)
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 the full answer
Related Book For
Accounting Information Systems
ISBN: 9780132871938
11th Edition
Authors: George H. Bodnar, William S. Hopwood
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
C++ Please use two .cpp files and and one .h file forthe code . Please follow the directions below. What if we could add colors like this: newColor = red + blue; Orwhat if we could compare athletes...
-
How well employees modify their thoughts and behavior to align with and support a new or changing environment is known as Multiple Choice proactive task performance. proficient task performance....
-
A force of P = 20 lb is applied perpendicular to the handle of the gooseneck wrecking bar as shown. If the coefficient of static friction between the bar and the wood is ? s = 0.5, determine the...
-
What three questions should form the basis for an interview strategy?
-
Let \(X\) be a Bessel process with dimension \(\delta <2\), starting at \(x>0\) and \(T_{0}=\inf \left\{t: X_{t}=0 ight\}\). Using time reversal theorem, prove that the density of \(T_{0}\) is...
-
Sales of tablet computers at Ted Glickman's electronics store in Washington, D. C., over the past 10 weeks are shown in the table below: a) Forecast demand for each week, including week 10, using...
-
There are two firms, Firm 1 and Firm 2. Firm 1's product has quality H and Firm 2's product has quality L, with 0
-
Robertos Honey Farm in Chile makes five types of honey: cream, filtered, pasteurized, mlange (a mixture of several types), and strained, which are sold in 1 or 0.5 kg glass containers, 1 kg and 0.75...
-
Jacoby S. borrows $200,000 to buy a house. The mortgage rate is 4.5 percent and the loan period is 30 years, with payments made monthly. What is his monthly mortgage payment?
-
Explain the measures to prevent contractual disputes.
-
Bob was killed in action while serving in Afghanistan. His duty station at the time he was deployed was Fort Benning, Georgia, where he and his family had lived for the previous five years. On July...
-
Discuss the antecedents of organizational citizenship behavior (OCB).
-
Following are the FCFS of a company with 120 million in debt, 40 million in cash and 60 million in outstanding shares. Year 1 30Mil 2 3 4 35 40 45 In year 4, growth rate stabilized at 4%, if r(wacc)...
-
You would like to retire in 30 years and you have calculated that you will need to save $2 million dollars by then to retire comfortably. How much must you put into your retirement savings account at...
-
Use the PW method to evaluate information in the table below and choose the best alternative between three molding machines which all have a useful life of 15 years and the company has a MARR of 12%...
-
The first national bank pays a 4% interest rate compound continuously. The effective annual rate paid by the bank is __________. a. 4.16% b. 4.20% c. 4.08% d. 4.12%
-
Discuss factors that should be considered in the organizational location of the internal audit function.
-
Eagle Airlines is headquartered in Chicago. The corporate administrative offices consist of 10 buildings in a complex that spreads over four square miles. The main data center is centrally located....
-
Does the size of a company have any impact on the approach taken to the systems design project? If your answer is Yes, explain.
-
List the most important three factors for you personally when deciding where to shop for clothes.
-
List all of the factors you can think of that people use when deciding where to shop for clothes.
-
Describe the car you, a friend, or family member had at age 30. a. What were the top two reasons this car was bought? b. What was the trigger for this purchase?
Study smarter with the SolutionInn App