CSE 1325 Java Coding and UML Diagrams Exercise

CSE 1325: Object-Oriented ProgrammingUniversity of Texas at Arlington
Summer 2021
Dr. Alex Dillho
Assignment 3
Assignment 3 will focus on inheritance and ArrayList.
Part 1
Create a UML diagram given the following specications. Player’s and Monster’s inherit
from an abstract Creature class.
public abstract class Creature
This class represents any creature in the game, whether it is player-controlled or not.
Instance Fields
The following instance elds are required. You should use getters and setters to access
them.
ˆ name : String
ˆ hp : int
ˆ ac : int
ˆ str : int
ˆ dex : int
ˆ con : int
Methods
public void takeDamage(int)
This method lowers the HP of the Creature by a value given by the int parameter. The
HP must not be allowed to go below 0. If the damage would reduce the Creature’s HP
below 0, set it to 0 instead.
public abstract void attack(Creature)
This method will be dened for all subclasses of Creature. See the entries for the subclasses
for more information.
Override Object.equals(Object)
This is necessary for determining if the custom objects are equal or not. You can use the
following pattern:
CSE 1325: Assignment 3
Dillho
public boolean equals(Object o) {
return o != null
&& getClass() == o.getClass()
&& name.equals(((Player) o).getName());
}
public class Player extends Creature
This class represents a Player-Controlled creature.
Instance Fields
Use accessors and mutators to access the following instance elds. You may re-use your
implementation of the Weapon class.
ˆ weapon : Weapon
Methods
private int rollHit()
Rolls to determine the attack to-hit value. An attack successfully hits if this value is
greater than or equal to the target’s AC. For Player’s, the total calculation is
d20 + DEX modier + Weapon bonus
That is, you rst roll a d20 and then add the DEX modier and bonus value from the
equipped Weapon. As a reminder, the stat modier is calculated by subtracting 5 from
the stat value and any stat cannot exceed 10.
public void attack(Creature)
This is the implementation of the abstract method declared in the super class. For the
Player, it should rst call rollHit() to determine if the attack hits. On a successful hit,
roll damage and call takeDamage(int) on the target.
For Player’s, damage is calculated by rolling their Weapon damage dice and adding their
STR modier. The damage cannot be negative.
public class Monster extends Creature
This class represents any Non Player Character (NPC).
Instance Fields
This class does not require any additional instance elds.
2
CSE 1325: Assignment 3
Dillho
Methods
private int rollHit()
Rolls to determine the attack to-hit value. An attack successfully hits if this value is
greater than or equal to the target’s AC. For Monster’s, the total calculation is
d20 + DEX modier
That is, you rst roll a d20 and then add the DEX modier. As a reminder, the stat
modier is calculated by subtracting 5 from the stat value and any stat cannot exceed 10.
public void attack(Creature)
This is the implementation of the abstract method declared in the super class. For the
Monster, it should rst call rollHit() to determine if the attack hits. On a successful
hit, roll damage and call takeDamage(int) on the target.
For Monster’s, damage is calculated by rolling a d6 damage dice and adding their STR
modier. The damage cannot be negative.
Part 2
Using the descriptions from part 1, implement the Creature, Player, and Monster classes.
You do not need to write a program (with main) to receive credit for this part.
Part 3
In the last part, you will create a program that will test the classes and methods created
in Part 2.
Create 2 Players and 3 Monsters. You are free to choose the name and stats for them
as well as the Weapon for the Players. Feel free to reference the Weapon list from the
project. You do not need to perform any le operations for this assignment. You can
also reference the following list of monsters when creating them. In main, add all of the
Creatures to an ArrayList of Creature.
Name
Air Elemental
Bandit
Centaur
Ghost
HP
90
11
45
45
AC
15
12
12
11
STR
7
5
9
3
DEX
10
6
7
6
CON
7
6
7
5
Create a method public void testCombat(ArrayList) which iterates through the
list and attempts to attack a random Creature. For each Creature, randomly select
another Creature that is not the same Creature. You should utilize the equals method
to compare the Creatures. If they are not equal, call the attack method to attack the
3
CSE 1325: Assignment 3
Dillho
other Creature. The program should print the results of any rolls and damage taken.
See the example output below.
Example Output
Vax’ildan attacks Bandit with Dagger (17 to hit)…HITS!
Bandit takes 3 points of damage.
Ghost attacks Jester (14 to hit)…MISSES!

Create a zip le using the name template LASTNAME_ID_A3.zip which includes the required .java les and diagram(s). Submit the zip le through Canvas.
4
Greataxe 1d12
Longsword 1d10
Warhammer1d8
Shortsword1d6
Dagger
1d4
0
1
2
3
4

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER