Do My Java Assignment using Eclipse and creating package Weapons
Question -
Create a new project, Create a package called Weapons.
Re-create the IWeapon interface here.
Create a method signature for strike() that returns an int. This will mimic a warrior using that weapon to strike.
Create three weapon classes inside the Weapons package that all implement IWeapon. Name these whatever you want but they need to support the follwingAn artillery type of weapon. Its strike value of must be 2.
An infantry type of weapon. Its strike value of must be 4.
A type of weapon used by cavalry. Its strike value of must be 8.
Create a package called Warriors
Create an abstract Warrior class
It should take an IWeapon in the constructor
It should have a private variable defined at the class level as an IWeapon. Set
...Read More
this to the IWeapon passed in through the constructor.
It should implement a public method called “attack()â€
attack() should call the strike method of IWeapon and return the strike value
There should be an abstract method defined called getHealth() that returns an int.
Create three warrior classes inside the Warriors package that all extend the abstract Warrior class
An ArtilleryWarrior. In the getHealth() method return 2;
An InfantryWarrior. In the getHealth() method return 4;
A CavalryWarrior. In the getHealth() method return 8;
Each should take an IWeapon in the constructor and pass it to the super class. Note: There is no need to keep an IWeapon in the subclasses.
Create a package called Main. In that package create a class Main that is the main
In your Main class, do the following:
Create an empty ArrayList of Warriors.
We will again use the Random() object.
Do the following 10 times:
Randomly choose a weapon using the nextInt() method:
If nextInt() returns 0, return a Warrior of type ArtilleryWarrior and pass it the artillery type of weapon in the constructor.
If nextInt() returns 1, return a Warrior of type InfantryWarrior and pass it the infantry type of weapon in the constructor.
If nextInt() returns 2, return a Warrior of type CavalryWarrior and pass it the cavalry type of weapon in the constructor.
Loop through the array list and print out the name of the warrior, weapon striking power and the health of each warrior.
An example of possible program output ….
class Warriors.InfantryWarrior attack strength is: 4 full health is: 4
class Warriors.CavalryWarrior attack strength is: 8 full health is: 8
class Warriors.InfantryWarrior attack strength is: 4 full health is: 4
class Warriors.ArtilleryWarrior attack strength is: 2 full health is: 2
class Warriors.CavalryWarrior attack strength is: 8 full health is: 8
class Warriors.InfantryWarrior attack strength is: 4 full health is: 4
class Warriors.InfantryWarrior attack strength is: 4 full health is: 4
class Warriors.ArtilleryWarrior attack strength is: 2 full health is: 2
class Warriors.ArtilleryWarrior attack strength is: 2 full health is: 2
class Warriors.CavalryWarrior attack strength is: 8 full health is: 8
...Read Less
Solution Preview - No Solution Preview Available
Original Question Documents
N/A
Having doubts on a term paper? Is a dissertation too lengthy to be done in a short time? Assignments are piling up? If you are nodding your head in a yes then discuss with our expert writers and get the best quote right away. Our online assignment help is known for being easy to avail and afford among students. Also, you just need to employ three steps to get our assignment writing services. We provide help for a wide range of subjects including management, finance, law, engineering, humanities, English etc. So, hurry up and enjoy our services. Get your quote, clear the payment and get your assignment done.
Found What You Need?
Scroll down to find more if you need to find our more features
Place Your Order