Problem 5: Monster Factory (10 points) (Game Dev) Create a Monster class that maintains a count of all monsters instantiated and includes a static method that generates a new random monster object. In software engineering, a method that generates new instances of classes based on configuration information is called the Factory pattern. UML Class Diagram: Monster - name: String - health: int - strength: int - xp: int + spawn(type:String): Monster + constructor (name: String, health: int, strength: int, xp: int) + getName(): String + getHealth(): int + getStrength(): int + getXP(): int + takeDamage(damage: int) + attack(hero: Player) + toString(): String Monster Constructor Summary: Constructor Description Monster(String name, int health, int strength, int xp) Creates Monster object with given name, health, strength. and xp. Monster Method API: Modifier and Type Method and Description void attack(Player hero) Monster attacks player, where player takes damage equal to monster strength. Display message: "%s attacks player for %d damage", name, strength int getHealth() Returns this monster's health String getName() Returns this monster's name int getStrength() Returns this monster's strength int getXP() Returns this monster's experience static Monster spawn(String type) Returns a monster object of given type for "goblin", "orc", or "troll" void takeDamage(int damage) health is decreased by given damage, but can't be a negative String toString() Returns a text representation of this account, formatted as: "[%s] HP: %d, STR: %d", name, health, strength Facts ● Monster types that may be spawned with following attribute values: ○ goblin, name="goblin", health=60, strength=8, xp=1 ○ orc, name="orc", health=100, strength=12, xp=3 ○ troll, name="troll", health=150, strength=15, xp=5 ● monster's attack() should invoke player's takeDamage() method. ● Consider using String.format() in your toString() Software Architecture: The Monster class is designed to be instantiated by Game class which is used to make Monster objects and Player objects. See the UML object diagram below: UML Object Diagram Tester Files: Use the MonsterTester.java file to test your implementation. Use the Game.java app to play a simple game using your Monster class. Sample Method Calls Sample Method Results Monster goblin = Monster.spawn("goblin"); Monster orc = Monster.spawn("orc"); Monster troll = Monster.spawn("troll"); System.out.println(goblin); System.out.println(orc); System.out.println(troll); [goblin] HP:60, STR:8 [orc] HP:100, STR:12 [troll] HP:150, STR:15
Solution to above problem is given below in their respective java files.
The implementation logic of the problem is provided in code comments of the program. In case of any problem regarding the implementation of question, write into comment section.
Monster.java
public class Monster { /* Instance variables / private String
name; private int health; private int strength; private int xp; /*
* @param name * @param health * @param strength * @param xp /
public Monster(String name, int health, int strength, int xp) {
super(); this.name = name; this.health = health; this.strength =
strength; this.xp = xp; } / return monster object of given
monsterName / public static Monster spawn(String monsterName) {
if(monsterName == "goblin") { return new Monster("goblin", 60, 8,
1); } if(monsterName == "orc") { return new Monster("orc", 100, 12,
3); } return new Monster("troll", 150, 15, 5); } / getter to return
name of the monster / public String getName() { return name; } /
getter to return health of the monster / public int getHealth() {
return health; } / getter to return strength of the monster /
public int getStrength() { return strength; } / getter to return
the XP of the monster / public int getXp() { return xp; } / this
method decreases the health by given damage points, this method
also * checks that damage should not be negative / public void
takeDamage(int damage) { if(damage > 0){ health = health -
damage; } } @Override public String toString() { return
String.format("[%s] HP: %d. STR: %d",name, health, strength); } /
this method implements the functionality of attack(int damage)
method, * monster attacks player, where player takes damage equal
to monster strength */ public void attack(Player hero) {
hero.takeDamage(this.strength);
System.out.println(String.format("%s attacks player for %d damage",
name, strength)); } }
Player.java
/* * Player class is implemented on user understanding of the
scenario, because * there is no information provided how player
class should be implemented. * This class needs to be implemented
to ensure the working of the attack(int: damage) method present in
monster Class * / public class Player{ / Instance variables */
private String playerName; private int playerHealth; public String
getPlayerName() { return playerName; } public void
setPlayerName(String playerName) { this.playerName = playerName; }
public int getPlayerHealth() { return playerHealth; } public void
setPlayerHealth(int playerHealth) { this.playerHealth =
playerHealth; } public void takeDamage(int damage) { playerHealth =
playerHealth - damage; } }
MonsterTester.java
public class MonsterTester { public static void main(String[]
args) { Monster goblin = Monster.spawn("goblin"); Monster orc =
Monster.spawn("orc"); Monster troll = Monster.spawn("troll");
System.out.println(goblin); System.out.println(orc);
System.out.println(troll); } }
Output:
Problem 5: Monster Factory (10 points) (Game Dev) Create a Monster class that maintains a count...
using C++ Requirements: . Classes you must create o Monster must be an abstract class Each monster has . an attack) o randomly generate a number between 0 and strength for each attack (Strength 10 would generate 0-10) add up all the damage done return total damage o o e a number of attacks . a number for strength used during attacking . a string representing the type » accessor for type o Goblin inherits from Monster type is "Goblin"...
Question 1. (Magician.java, Healer.java, Fighter.java, HeroTester.java) Consider the abstract hero class and the three subclasses shown below. Review the hero class to see how it works (it’s in the project/package for you already). Your job is to implement the following subclasses. Each of the subclasses has an extra data field that relates to their specific hero talent. Some help with these special talents and other methods are below. Fighter: ‐The fighter has an extra data field called Strength and a...
Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of...
I need help with this problem. Using Python please. Thanks Construct a class “Monster” with the following attributes: self.name (a string) self.type (a string, default is ‘Normal’) self.current_hp (int, starts out equal to max_hp) self.max_hp (int, is given as input when the class instance is created, default is 20) self.exp (int, starts at 0, is increased by fighting) self.attacks (a dict of all known attacks) self.possible_attacks (a dictionary of all possible attacks The dictionary of possible_attacks will map the name...
HIGHEST SUBMISSION Vlew All Submissions Submission 17 Submitted on 6/10/2019 12 35 PM by Jenna Saleh DESCRIPTION Objectives To write a classes based on sets of specifications To write a main class to be used in a multi-class Java program To use inheritance to extend a class (optional, EC) To override methods in subclasses (optional, EC) Groups You may work with a partner on this assignment. A header comment (In every Java file) should include authors (group members) and collaborators...
Classes A Customer Points class maintains information about a customer. This information is the customer name (entire name as a String) and the amount of points (as an int) the customer has accrued. Methods: Constructor: Receives a name and sets the name field to the received name and sets the points field to 0 (zero). getName: Returns the customer's name getPoints: Returns the customer's current points toString: Returns a String representation of the current state in the form-name points, i.e....
java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...
Base Class enum HeroType {WARRIOR, ELF, WIZARD}; const double MAX_HEALTH = 100.0; class Character { protected: HeroType type; string name; double health; double attackStrength; public: Character(HeroType type, const string &name, double health, double attackStrength); HeroType getType() const; const string & getName() const; /* Returns the whole number of the health value (static_cast to int). */ int getHealth() const; void setHealth(double h); /* Returns true if getHealth() returns an integer greater than 0, otherwise false */ bool isAlive() const; virtual void...
Last picture is the tester program! In this Assignment, you will create a Student class and a Faculty class, and assign them as subclasses of the superclass UHPerson. The details of these classes are in the UML diagram below: UHPerson - name : String - id : int + setName(String) : void + getName(): String + setID(int) : void + getID(): int + toString(): String Faculty Student - facultyList : ArrayList<Faculty - rank: String -office Hours : String - studentList...
Rewrite following code down below using Factory Pattern. -------------------------Staff.java--------------------------- import java.util.*; public class Staff extends Employee { private int HourlyRate; /**Constructor Staff which initiates the values*/ public Staff() { super(); HourlyRate=0; } /**Overloaded constructor method * @param ln last name * @param fn first name * @param ID Employee ID * @param sex Sex * @param hireDate Hired Date * @param hourlyRate Hourly rate for the work...