In this homework, you will practice:
After hearing that you have taken the best class at Georgia Tech, CS 1331, an important video game company has hired you to develop the framework for their latest video game, Fantasy Quest 3: Return of Zardaneck.
Download the abstract class Character.java. Implement all the missing methods of the abstract class, as well as implementing the subclasses Fighter.java, Rogue.java, Wizard.java, and Cleric.java. You will need to create these other classes from scratch.
Do not modify the code we give you.
Implement the getter and setter methods that have been partially provided.
String name, int level, int strength, int dexterity, int intelligence, int wisdom
. The health
variable should start equal to five times the character level, and should never go above that. If the health
variable ever goes below 0, isDead
should be set to true
and the health
variable be reset to 0.strength
, then dexterity
, then intelligence
, then wisdom
). You do not have to use explicit constructor invocation (aka constructor delegation) for this.This class should extend Character
and implement all of its abstract methods.
Implement the attack(Character c)
method. The attack method of Fighter
should decrement the health of the parameter character by 10 plus the fighter’s strength variable. If the character’s isDead
variable is true, this method should do nothing besides printing "Cannot attack a dead character"
to the console.
Implement the levelUp()
method. This method should increase the character’s level
by 1, reset the health
to it’s maximum (5 times the level
), increase strength
by 2, and all other stats by 1.
a toString()
method that returns a string with format "Level (level) fighter named (name) with (strength) strength, (dexterity) dexterity, (intelligence) intelligence, and (wisdom) wisdom."
Implement 2 constructors coorresponding with each of the constructors of the superclass.
This class should extend Character
and implement all of its abstract methods.
Implement the attack(Character c)
method. The attack method of Rogue
should decrement the health of the parameter character by 6 plus the rogue’s dexterity variable. If the character’s isDead
variable is true, this method should do nothing besides printing "Cannot attack a dead character"
to the console.
Implement the levelUp()
method. This method should increase the character’s level
by 1, reset the health
to it’s maximum (5 times the level
), increase dexterity
by 3, and all other stats by 2.
a toString()
method that returns a string with format "Level (level) rogue named (name) with (strength) strength, (dexterity) dexterity, (intelligence) intelligence, and (wisdom) wisdom."
Implement 2 constructors coorresponding with each of the constructors of the superclass.
This class should extend Character
and implement all of its abstract methods.
Implement the attack(Character c)
method. The attack method of Cleric
should decrement the health of the parameter character by 6 plus the cleric’s wisdom variable. If the character’s isDead
variable is true, this method should do nothing besides printing "Cannot attack a dead character"
to the console.
Implement the levelUp()
method. This method should increase the character’s level
by 1, reset the health
to it’s maximum (5 times the level
), increase wisdom
by 2, and all other stats by 1.
Create a new method called heal(Character c)
which increases the parameter characters health by 6 plus the clerics wisdom variable, but not beyond their maximum health (5 times their level). If a character is dead, do nothing except print "Cannot heal a dead character"
to the console.
a toString()
method that returns a string with format "Level (level) cleric named (name) with (strength) strength, (dexterity) dexterity, (intelligence) intelligence, and (wisdom) wisdom."
Implement 2 constructors coorresponding with each of the constructors of the superclass.
This class should extend Character
and implement all of its abstract methods.
Implement the attack(Character c)
method. The attack method of Wizard
should decrement the health of the parameter character by a 4 plus the wizard’s intelligence variable. If the character’s isDead
variable is true, this method should do nothing besides printing "Cannot attack a dead character"
to the console.
Implement the levelUp()
method. This method should increase the character’s level
by 1, reset the health
to it’s maximum (5 times the level
), increase intelligence
by 2, and all other stats by 1.
Create a new method called multiAttack(Character ... c)
which decreases each character in the parameter’s health by 2 plus the wizard’s intelligence variable (different values for each character). If a character is dead, do nothing to that character except print "Cannot damage a dead character"
to the console.
a toString()
method that returns a string with format "Level (level) wizard named (name) with (strength) strength, (dexterity) dexterity, (intelligence) intelligence, and (wisdom) wisdom."
Implement 2 constructors coorresponding with each of the constructors of the superclass.
Character
.Character.isDead
.health
never goes above level
* 5.Character
.attack()
method for Rogue
, Fighter
, Wizard
, and Cleric
.levelUp()
method for Rogue
, Fighter
, Wizard
, and Cleric
.Wizard.multiAttack()
Cleric.heal()
.toString()
methods for each class.Creating a Game
class with a main
method to create a simulation to test of all the methods would be the best course of action. Do not submit this.
If anything seems confusing, read through the entire description and instructions again. As always, feel free to contact your TAs, post on Piazza, or come in for office hours. In addition, here are some tips specific to this homework:
Import java.util.Random
, but not anything that trivializes the assignment.
Use the java API when you need help thinking of how to do something.
Test things out in jshell!
You will need to write Javadoc comments and watch for checkstyle errors with your submission.
Every class should have a class level Javadoc that includes @author <GT Username>
.
Every public method should have a Javadoc explaining what the method does and includes any of the following tags if applicable:
@param <parameter name> <brief description of parameter>
@returns <brief description of what is returned>
@throws <Exception> <brief explanation of when the given exception is thrown>
See the CS 1331 Style Guide for details.
For each of your homwork assignments we will run checkstyle and deduct one point for every checkstyle error.
For this homework the checkstyle cap is 50, meaning you can lose up to 50 points on this assignment due to style errors. This limit will increase on the next homework.
java -jar checkstyle-6.2.2.jar *.java
.java -jar checkstyle-6.2.2.jar -j *.java
.When completing homeworks for CS1331 you may talk with other students about:
OKAY: “Hey, I’m really confused on how we are supposed to implement this part of the homework. What strategies/resources did you use to solve it?”
BY NO MEANS OKAY: “Hey… the homework is due in like 20 minutes… Can I see your code? I promise won’t copy it directly!”
In addition to the above rules, note that it is not allowed to upload your code to any sort of public repository. This could be considered an Honor Code violation, even if it is after the homework is due.
Submit all of your Java source files, as well as the Character.java
file we provided. When we download your submission from Canvas we should have everything we need to test your code. You should do this in an empty directory after submission to ensure that you have submitted complete, working code. You can submit as many times as you want, so feel free to submit as you make substantial progress on the homework. We only grade your last submission, meaning we will ignore any previous submissions.
As always, late submissions will not be accepted and non-compiling code will be given a score of 0. For this reason, we recommend submitting early and then confirming that you submitted ALL of the necessary files by re-downloading your file(s) and compiling/running them.