Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Class hierarchy This is the simplified class diagram for the set of classes and interfaces you are to define: GameVisual bstractGameVisual tem Key Spider Adventurer

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Class hierarchy This is the simplified class diagram for the set of classes and interfaces you are to define: GameVisual bstractGameVisual tem Key Spider Adventurer Moveable Backpack Interfaces Your program is to define the following two interfaces: Interface GameVisual: This interface defines the methods necessary for all game objects that are to be rendered on the screen. It consists of the following methods: getChar () : Returns a character to display on the screen getX , getY ): Return the x or y position of the game object setX (int x), setY (int y) Set the x or y position of game object toString () Interface Movable: This interface defines the move ) method necessary for every movable game object to make a legal move in the world. This method takes no arguments and does not return anything. When implemented in a class, it will mutate the state of the object that implements it. Classes Your program is to define six classes: An abstract class AbstractGameVisual that implements the GameVisual interface. It needs to provide x and y position of a game object and define all methods other than getChar method. In addition, it should contain a parameterless constructor. A concrete class Key that is an AbstractGameVisual type, with an additional name component denoted by the constant character 'K' -the same character for all objects of this type. Defines a parameterless constructor and getChar () method. A concrete class Item that is an AbstractGameVisual type, with 3 additional components: each item of this type has its individual weight, point value, and a char name component. Defines a parameterless constructor, all setters and getters, and tostring) methods. A concrete class Backpack that is not related to other types by inheritance hierarchy and will be used to create objects that contain all artifacts collected by an adventurer (one backpack per adventurer) Each backpack object has a preset maximum weight it can carry. This maximum weight is assigned via a parameterized constructor. You can think of this class as a list of items. Defines getWeight ) that returns the total weight of all items placed in the backpack, getMaxSize () that returns the maximum weight the backpack can carry, addItem (Item someItem) to add an item to a backpack, and toString ) methods. A concrete class Spider that is an AbstractGameVisual type with an additional name component denoted by the constant character 'S the same character for all objects of this type. Defines a parameterless constructor and getChar ) method. In addition, Spider is also a Movable type and implements the Movable interface. The move method in this class should move a spider object from its current location to a new location following the zig-zag pattern. However, spider objects do not move upon every call to move, but rather every 10th time the method is called. The way the animation is written right now is based on a timer, so every time a timer ticks, the move method is called but we don't want to move the spider that often. The 10th call to move changes the spider object's location two cells to the left. The next 10th call to move changes the spider object's location two cells up. Then, the pattern gets repeated. This is the picture of the pattern, where bold indicates the original location: S.S To support the move pattern, you may define additional properties in this class that help remember/determine the object's direction and the move call number A concrete class Adventurer that is an AbstractGameVisual type, with an additional name component denoted by the constant character A-the same character for all objects of this type. Each adventurer object also has his own backpack, which for the purposes of this simulations should be preset to 1000 units of weight in the parameterless constructor. Each adventurer object keeps on collecting Item objects into his backpack until his backpack capacity is reached. He also should collect one Key object (but no more than one) because without the key, he won't be able to open any of the boxes he may collect. Defines hasSpace (double newItemsWeight) that informs the user whether the adventurer's backpack has enough space for the new item, addItem (Item someItem) to add an item to a backpack an adventurer is carrying, addKey ) that changes the adventurer object to indicate he is in possession of a key, hasKey () that informs the user whether the adventurer has a key, getChar ()and toString() methods. In addition, Adventurer is also a Movable type and implements the Movable interface. The move method in this class should move an adventurer object from its current location to a new location following the square spiral pattern. The 15t call to move changes the adventurer object's location one cell to the left. The 2nd and 3rd call to move change the adventurer object's location one cell up. The 4th 5th, 6th call to move change the adventurer object's location one cell to the right. The 7th, 8th, gth, 10th call to move change the adventurer object's location one cell down. Then, the pattern gets repeated. This is the picture of the pattern, where bold indicates the original location: To support the move pattern, you may define additional properties in this class that help remember the object's direction and the move call number. When the simulation runs, objects are consumed by spiders or collected by adventurers only if a movable object lands in the same cell. This logic is already implemented and this note is just an explanatory note so that you understand the output. Your code should be organized in the following manner: All fields are declared before all constructors All constructors are declared before all other methods. All static fields are declared before all non-static fields. All static methods are declared before all non-static methods Among the same type of entity (constructors, instance methods, static methods, instance fields, Class hierarchy This is the simplified class diagram for the set of classes and interfaces you are to define: GameVisual bstractGameVisual tem Key Spider Adventurer Moveable Backpack Interfaces Your program is to define the following two interfaces: Interface GameVisual: This interface defines the methods necessary for all game objects that are to be rendered on the screen. It consists of the following methods: getChar () : Returns a character to display on the screen getX , getY ): Return the x or y position of the game object setX (int x), setY (int y) Set the x or y position of game object toString () Interface Movable: This interface defines the move ) method necessary for every movable game object to make a legal move in the world. This method takes no arguments and does not return anything. When implemented in a class, it will mutate the state of the object that implements it. Classes Your program is to define six classes: An abstract class AbstractGameVisual that implements the GameVisual interface. It needs to provide x and y position of a game object and define all methods other than getChar method. In addition, it should contain a parameterless constructor. A concrete class Key that is an AbstractGameVisual type, with an additional name component denoted by the constant character 'K' -the same character for all objects of this type. Defines a parameterless constructor and getChar () method. A concrete class Item that is an AbstractGameVisual type, with 3 additional components: each item of this type has its individual weight, point value, and a char name component. Defines a parameterless constructor, all setters and getters, and tostring) methods. A concrete class Backpack that is not related to other types by inheritance hierarchy and will be used to create objects that contain all artifacts collected by an adventurer (one backpack per adventurer) Each backpack object has a preset maximum weight it can carry. This maximum weight is assigned via a parameterized constructor. You can think of this class as a list of items. Defines getWeight ) that returns the total weight of all items placed in the backpack, getMaxSize () that returns the maximum weight the backpack can carry, addItem (Item someItem) to add an item to a backpack, and toString ) methods. A concrete class Spider that is an AbstractGameVisual type with an additional name component denoted by the constant character 'S the same character for all objects of this type. Defines a parameterless constructor and getChar ) method. In addition, Spider is also a Movable type and implements the Movable interface. The move method in this class should move a spider object from its current location to a new location following the zig-zag pattern. However, spider objects do not move upon every call to move, but rather every 10th time the method is called. The way the animation is written right now is based on a timer, so every time a timer ticks, the move method is called but we don't want to move the spider that often. The 10th call to move changes the spider object's location two cells to the left. The next 10th call to move changes the spider object's location two cells up. Then, the pattern gets repeated. This is the picture of the pattern, where bold indicates the original location: S.S To support the move pattern, you may define additional properties in this class that help remember/determine the object's direction and the move call number A concrete class Adventurer that is an AbstractGameVisual type, with an additional name component denoted by the constant character A-the same character for all objects of this type. Each adventurer object also has his own backpack, which for the purposes of this simulations should be preset to 1000 units of weight in the parameterless constructor. Each adventurer object keeps on collecting Item objects into his backpack until his backpack capacity is reached. He also should collect one Key object (but no more than one) because without the key, he won't be able to open any of the boxes he may collect. Defines hasSpace (double newItemsWeight) that informs the user whether the adventurer's backpack has enough space for the new item, addItem (Item someItem) to add an item to a backpack an adventurer is carrying, addKey ) that changes the adventurer object to indicate he is in possession of a key, hasKey () that informs the user whether the adventurer has a key, getChar ()and toString() methods. In addition, Adventurer is also a Movable type and implements the Movable interface. The move method in this class should move an adventurer object from its current location to a new location following the square spiral pattern. The 15t call to move changes the adventurer object's location one cell to the left. The 2nd and 3rd call to move change the adventurer object's location one cell up. The 4th 5th, 6th call to move change the adventurer object's location one cell to the right. The 7th, 8th, gth, 10th call to move change the adventurer object's location one cell down. Then, the pattern gets repeated. This is the picture of the pattern, where bold indicates the original location: To support the move pattern, you may define additional properties in this class that help remember the object's direction and the move call number. When the simulation runs, objects are consumed by spiders or collected by adventurers only if a movable object lands in the same cell. This logic is already implemented and this note is just an explanatory note so that you understand the output. Your code should be organized in the following manner: All fields are declared before all constructors All constructors are declared before all other methods. All static fields are declared before all non-static fields. All static methods are declared before all non-static methods Among the same type of entity (constructors, instance methods, static methods, instance fields

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Distinguish the three measures used in marketing research.

Answered: 1 week ago

Question

Develop a program for effectively managing diversity. page 303

Answered: 1 week ago

Question

List the common methods used in selecting human resources. page 239

Answered: 1 week ago