Java

OOP GUIDE / WORK

 

RANGEDWEAPON CLASS 2

 

Topics

  • Object array
  • Polymorphism
  • Inheritance

 

 

TASK – PART 1 – SETUP

 

You will need to copy an paste the following classes from the RangedWeapon class solution and work sections.

 

·               Weapon (from the work section)

·               Projectile (from the solution section)

·               RangedWeapon (from the solution section)

 

 

TASK – PART 2 – MORE SETUP

 

Copy and paste the following Tester class.  (Feel free to rename it Tester2 if Tester is already taken.)

Run the file to see what happens.

 

public class Tester

{

     public static void main(String[] args)

     {

        Weapon w1 = new Weapon("Sword",6,8,0);

        System.out.println(w1);

      

        Projectile dart = new Projectile("Dart", 1);

        RangedWeapon w2 = new RangedWeapon("Blowpipe",2,3,0,dart);

        System.out.println(dart);

        System.out.println(w2);

              

        Projectile arrow = new Projectile("Arrow", 2);

        RangedWeapon w3 = new RangedWeapon("Bow",3,4,0,arrow);

        System.out.println(arrow);

        System.out.println(w3);

       

        Weapon w4 = new Weapon("Axe",7,9,0);

        System.out.println(w4);

       

        Weapon w5 = new Weapon("Spear",10,11,0);

        System.out.println(w5);

        

        Weapon w6 = new Weapon("Morning Star",5,10,0);

        System.out.println(w6);

       

        Projectile sarrow = new Projectile("Silver Arrow", 3);

        RangedWeapon w7 = new RangedWeapon("Crossbow",3,4,0,sarrow);

        System.out.println(w7);

       

        Weapon w8 = new Weapon("Dagger",2,3,0);

        System.out.println(w8);

       

        //Example of damage done by w6 on three occasions.

        System.out.println(w6.getDamageAmount());

        System.out.println(w6.getDamageAmount());

        System.out.println(w6.getDamageAmount());

     }

}

 

 

 

TASK – PART 3 – POLYMORPHISM

 

In the main function from the above Tester class, do the following:

·               Add a Weapon array of size 8. 

·               Place the 8 weapons (w1 to w8) into the array.

·               Simulate a round of attack using each weapon.  Use a loop.  Output the damage done by each weapon and the total damage from the round.

·               Place the above loop inside another loop to simulate 20 rounds of attack.

·               Total the entire damage done and output it to screen.