You are part of a team writing classes for the different game objects in a video game. In this assessment you are given a superclass (Human.java), two subclasses (Warrior.java and Wizard.java) and a test application (TestGameObjects.java). Both the Warrior and the Wizard classes need to be able to calculate stealth. This needs to be done in the method getStealth. This method has an integer parameter (dexterity) and returns an integer. Refer to the test application to see how the method is used. The Warrior and Wizard classes calculate stealth differently: The Warrior's stealth is equal to dexterity times strength (dexterity * strength) while the Wizard's stealth is equal to three times dexterity times intelligence (3 * dexterity * intelligence). You need to write an interface with the method getStealth, and then modify the superclass and subclasses to implement this interface. You also need to test the validity of the object ID. The object ID must consist of the character 'W' followed by 4 digits (eg.: "W1234"). If the object ID is invalid you need to throw an InvalidObjectIDException. You need to write the exception class. It must be an unchecked exception. Lastly you need to write a test application to test the validity testing. In this application you must create objects with
java
You are part of a team writing classes for the different game objects in a video game.
In this assessment you are given a superclass (Human.java), two subclasses (Warrior.java and Wizard.java) and a test application (TestGameObjects.java). Both the Warrior and the Wizard classes need to be able to calculate stealth. This needs to be done in the method getStealth. This method has an integer parameter (dexterity) and returns an integer. Refer to the test application to see how the method is used. The Warrior and Wizard classes calculate stealth differently: The Warrior's stealth is equal to dexterity times strength (dexterity * strength) while the Wizard's stealth is equal to three times dexterity times intelligence (3 * dexterity * intelligence). You need to write an interface with the method getStealth, and then modify the superclass and subclasses to implement this interface.
You also need to test the validity of the object ID. The object ID must consist of the character 'W' followed by 4 digits (eg.: "W1234"). If the object ID is invalid you need to throw an InvalidObjectIDException. You need to write the exception class. It must be an unchecked exception. Lastly you need to write a test application to test the validity testing. In this application you must create objects with the following invalid IDs: "12345", "W12345" and "W1b23". Each object must be created in a separate try-catch block.
public class TestGameObjects { public static void main(String[] args) { Warrior w1 = new Warrior("W1234", 25); Wizard z1 = new Wizard("W2467", 35); System.out.println("Warrior w1 with dexterity 50 has stealth: " + w1.getStealth(50)); System.out.println("Wizard z1 with dexterity 25 has stealth: " + z1.getStealth(25)); } }
public class Warrior extends Human { private int strength; public Warrior() { this("W0000",1); } public Warrior(String id, int strength) { super(id); setStrength(strength); } public void setStrength(int s) { strength = s; } public int getStrength() { return strength; } }
public class Wizard extends Human { private int intelligence; public Wizard() { this("W0000",1); } public Wizard(String id, int intel) { super(id); setIntelligence(intel); } public void setIntelligence(int intel) { intelligence = intel; } public int getIntelligence() { return intelligence; } }
Public class Human { private String objectID; public Human() { this("W0000"); } public Human(String id) { setObjectID(id); } public void setObjectID(String id) { objectID = id; } public String getObjectID() { return objectID; } }
Step by step
Solved in 2 steps