Homework Assignment #14 (Inheritance)

In this assignment you are tasked with creating three classes to represent different character types for a video game: Warrior, Paladin, and Berserker. Both Paladins and Berserkers are types of Warriors (make sure to use inheritance!). Each character has the following stats: strength, defense, magic, and health, which are all integers. Every character also has a name. All warriors have the ability to announce themselves, and to report on their stats. Paladins also have the special ability to heal themselves. When they heal themselves, they lose 5 magic and gain 10 health (the method should also display a message and then display the character's stats). Berserkers have the ability to berserk, and when they do, they lose 10 defense and gain 10 strength (again, the method should also display a message and then display the character's stats). Each class should have at least two constructors: one which takes a string for a name and four integers for the stats, and one which only takes a string, using the default values for each of the stats. (The default values for "Warrior" listed below are for warriors who are not paladins or berserkers.)

Class Strength Defense Magic Health
Warrior 15 15 10 50
Paladin 13 17 20 40
Berserker 18 12 5 70

Like last time, I will give you the code for a tester script and the desired output. Here is the tester code:

public class WarriorTester {
	public static void main(String args[]) {
		Warrior Yim = new Warrior("Yim Wing-chun");
		Paladin Joan = new Paladin("Joan of Ark");
		Berserker Beowulf = new Berserker("Beowulf", 17, 18, 5, 95);
		
		Yim.announce();
		Yim.stats();
		
		Joan.announce();
		Joan.stats();
		Joan.heal();
		
		Beowulf.announce();
		Beowulf.stats();
		Beowulf.berserk();
	}
}

And here is the desired output:

Greetings! I am Yim Wing-chun!
Strength: 15
Defense: 15
Magic: 10
Health: 50
I am Joan of Ark. Blessings be upon you.
Strength: 13
Defense: 17
Magic: 20
Health: 40
Joan of Ark casts a spell and regains some health.
Strength: 13
Defense: 17
Magic: 15
Health: 50
I'm Beowulf. Don't make me angry.
Strength: 17
Defense: 18
Magic: 5
Health: 95
Beowulf goes into a berserker rage!
Strength: 27
Defense: 8
Magic: 5
Health: 95

When you've completed the assignment, make sure that the files containing the source code have read permissions set for everyone, and that the compiled classes file have read and execute permissions set for everyone. Then send an e-mail to me and Sudhakar (our e-mail addresses are on the syllabus) including the paths and the filenames for the source code and the compiled files.

This assignment is due Monday, July 21st before class.