diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89f9ac0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +out/ diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..29cba1f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,9 @@ - + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index bc79c46..936d8ed 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Polymorphism Exercise
    -
  1. Create a Person class with attributes String name and int health. +
  2. Create an abstract Person class with attributes String name and int health. Create a constructor with parameter name and set health = 100;. Create getter methods for name and health and setter method for health.
  3. @@ -8,7 +8,7 @@ Create getter methods for name and health and weapon;. Create a constructor with parameter name. Call the super constructor with the name. Create a setter method setWeapon(Weapon weapon);. -
  4. Create a Weapon class with one abstract method strike(Warrior +
  5. Create a Weapon interface with one abstract method strike(Warrior opponent); an no attributes.
  6. To the Warrior class. Add a decHealth method with a single parameter int amt. Set the health value to Math.max(0, health – diff --git a/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Main.class b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Main.class new file mode 100644 index 0000000..8baee84 Binary files /dev/null and b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Main.class differ diff --git a/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Person.class b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Person.class new file mode 100644 index 0000000..dbf17e6 Binary files /dev/null and b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Person.class differ diff --git a/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Sword.class b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Sword.class new file mode 100644 index 0000000..6629f96 Binary files /dev/null and b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Sword.class differ diff --git a/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Wand.class b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Wand.class new file mode 100644 index 0000000..7010a36 Binary files /dev/null and b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Wand.class differ diff --git a/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Warrior.class b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Warrior.class new file mode 100644 index 0000000..0796460 Binary files /dev/null and b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Warrior.class differ diff --git a/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Weapon.class b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Weapon.class new file mode 100644 index 0000000..44ed466 Binary files /dev/null and b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Weapon.class differ diff --git a/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Whip.class b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Whip.class new file mode 100644 index 0000000..a0a76d8 Binary files /dev/null and b/out/production/JavaIntro4Debrief/com/example/polymorphism_exercise/Whip.class differ diff --git a/src/com/example/polymorphism_exercise/Weapons.java b/src/com/example/polymorphism_exercise/Weapons.java index afbec4d..98795da 100644 --- a/src/com/example/polymorphism_exercise/Weapons.java +++ b/src/com/example/polymorphism_exercise/Weapons.java @@ -1,5 +1,5 @@ package com.example.polymorphism_exercise; -class Sword extends Weapon { +class Sword implements Weapon { public void strike(Warrior opponent) { System.out.println("Slashing " + opponent.getName()); opponent.decHealth(5); @@ -7,7 +7,7 @@ public void strike(Warrior opponent) { } } -class Wand extends Weapon { +class Wand implements Weapon { public void strike(Warrior opponent) { System.out.println("Mesmerizing " + opponent.getName()); opponent.decHealth(3); @@ -15,7 +15,7 @@ public void strike(Warrior opponent) { } } -class Whip extends Weapon { +class Whip implements Weapon { public void strike(Warrior opponent) { System.out.println("Snapping " + opponent.getName()); opponent.decHealth(4);