Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help implementing this parts to my code, I already tried to some, but im stuck here is Zombie File: public class Zombie { private

Need help implementing this parts to my code, I already tried to some, but im stuck

image text in transcribed

image text in transcribed

here is Zombie File:

public class Zombie { private String zombieType; private String zombieWeakness; //private weapon zombieWeapon; static private String [] zombies = {"Chemical", "Radiation", "Parasite"}; static private String [] weaknesses = {"Intelligence", "Speed", "Fire"}; // Constructor public Zombie() { this.setZombieType("Chemical"); this.setZombieWeakness("Intelligence"); //random Zombies and Weaknesses this.setZombieType(zombies[random(0, zombies.length - 1)]); this.setZombieWeakness(weaknesses[random(0, weaknesses.length - 1)]); } // Generates random values between given range private int random(int min, int max) { return (int) (Math.random() * (max - min + 1) + min); } public Zombie(String zTyp, String zWeak ){ this.setZombieType(zTyp); this.setZombieWeakness(zWeak); } @Override public String toString() { String str="Zombie Type: "+ this.zombieType+" Zombie Weakness: "+ this.zombieWeakness; return str; } public int attack() { int attackIndex = 0; for (int i = 0; i

// // // Zombie attacked // // public void getAttacked(String hunterAttack) { // // } // Setters

public void setZombieType(String zombieType) { this.zombieType = zombieType; }

public void setZombieWeakness(String zombieWeakness) { this.zombieWeakness = zombieWeakness; } // Getters public String getZombieType() { return zombieType; }

public String getZombieWeakness() { return zombieWeakness; }

} Weapon file:

public class Weapon { private String weaponName; static protected int weaponStrength; //constructor public Weapon() { // Weapon Strength from 1 to 3 int min = 1, max = 3; this.setWeaponName("random"); this.setWeaponStrength(random(min, max)); } // Generates random values between given range private int random(int min, int max) { return (int) (Math.random() * (max - min + 1) + min); } public Weapon(String wNa, int wStr ){ this.setWeaponName(wNa); this.setWeaponStrength(wStr); } @Override public String toString() { String str="weapon Name: "+ this.weaponName+" Weapon Strength: "+ Weapon.weaponStrength; return str; } // Setters

public void setWeaponName(String weaponName) { this.weaponName = weaponName; }

public void setWeaponStrength(int weaponStrength) { Weapon.weaponStrength = weaponStrength; } // Getters

public String getWeaponName() { return weaponName; }

public int getWeaponStrength() { return weaponStrength; }

}

Let me know if you need something else from my code, Thanks.

At this level, you will leave the method getAttacked without implementation "will be implemented in the next phase". The Attack method will return an integer which presents the amount of health the hunter will lose when he/she will be attacked by the zombie. This integer is calculated as following: Zombie type (weapon is used) (weapon is Not used) Chemical attackStrength*1* weaponStrength attackStrength*1*1 Radiation attackStrength*2* weaponStrength attackStrength*2*1 Parasite attackStrength*3* weaponStrength attackStrength*3*1 The weaponStrength is a data member in the class Weapon which will be explained later (you will need to use getWeaponStrength to have access to it). The table shows that when weapon is used the damage will be doubled. When the attack method is called, the method should state if the weapon was used or not and it should print the amount of deducted health of the hunter (the returned integer) I am sure you have noticed that there is an object of a type weapon in each class of the 4 classes. This class is described as shown below in the UML. Weapon weapon Name: String weaponStrength: int + + + Weapon (String) setWeaponName(String):void set weaponStrength(int): void getWeaponNames(): String getWeaponStrength():int toString(): String + + + The is class works as following: The weaponStrength should be set to a random value in the range 1 to 3 When a weapon object is created (which will be done inside one of the 4 classes), the name of the class should be passed to the constructor. Use the name of the class to assign the name of the weapon depending of the type of the creature (zombie, vampire, monster, witch). If the passed string is zombie, the weaponName should be set to "Cricket Bat". If the passed string is vampire, the weaponName should be set to "Quarterstaff". If the passed string is monster, the weapon Name should be set to "flail. If the passed string is witch, the weapon Name should be set to "Wand". . At this level, you will leave the method getAttacked without implementation "will be implemented in the next phase". The Attack method will return an integer which presents the amount of health the hunter will lose when he/she will be attacked by the zombie. This integer is calculated as following: Zombie type (weapon is used) (weapon is Not used) Chemical attackStrength*1* weaponStrength attackStrength*1*1 Radiation attackStrength*2* weaponStrength attackStrength*2*1 Parasite attackStrength*3* weaponStrength attackStrength*3*1 The weaponStrength is a data member in the class Weapon which will be explained later (you will need to use getWeaponStrength to have access to it). The table shows that when weapon is used the damage will be doubled. When the attack method is called, the method should state if the weapon was used or not and it should print the amount of deducted health of the hunter (the returned integer) I am sure you have noticed that there is an object of a type weapon in each class of the 4 classes. This class is described as shown below in the UML. Weapon weapon Name: String weaponStrength: int + + + Weapon (String) setWeaponName(String):void set weaponStrength(int): void getWeaponNames(): String getWeaponStrength():int toString(): String + + + The is class works as following: The weaponStrength should be set to a random value in the range 1 to 3 When a weapon object is created (which will be done inside one of the 4 classes), the name of the class should be passed to the constructor. Use the name of the class to assign the name of the weapon depending of the type of the creature (zombie, vampire, monster, witch). If the passed string is zombie, the weaponName should be set to "Cricket Bat". If the passed string is vampire, the weaponName should be set to "Quarterstaff". If the passed string is monster, the weapon Name should be set to "flail. If the passed string is witch, the weapon Name should be set to "Wand

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions