Question: JAVA CODE - Need help with this project, I'm stuck here I will include the intructions I need to complete and the code I have,

JAVA CODE - Need help with this project, I'm stuck here I will include the intructions I need to complete and the code I have, I hope someone can help, Thanks.

JAVA CODE - Need help with this project, I'm stuck here I

will include the intructions I need to complete and the code Ihave, I hope someone can help, Thanks. MainClass.java Creature.java public class Creature

MainClass.java

{ private int attackStrength; private boolean boss; private boolean life; private int

Creature.java

public class Creature { private int attackStrength; private boolean boss; private boolean life; private int size; private int health; // Constructor public Creature(boolean boss) { // creature ranges from 25 to 100 int min = 25, max = 100; // creature AttackStrength from 1 to 3 int aMin = 1, aMax = 3; // if boss, states equal 100 if(boss) { min = 100; max = 100; aMin = 3; aMax = 3; } // creature generating randomly this.setAttackStrength(attRandom(aMin, aMax)); this.setBoss(boss); this.setLife(true); this.setSize(random(min, max)); this.setHealth(random(min, max)); } // Generates random values between given range private int random(int min, int max) { return (int) (Math.random() * (max - min + 1) + min); } // Generates random values for AttackStrength private int attRandom(int aMin, int aMax) { return (int) (Math.random() * (aMax - aMin + 1) + aMin); } public Creature(int aStre , boolean boss, boolean life, int siz, int hth){ this.setAttackStrength(aStre); this.setBoss(boss); this.setLife(life); this.setSize(siz); this.setHealth(hth); } @Override public String toString() { String str="Attack Strength: "+ this.attackStrength+" Boss: "+ this.boss+" Life: "+ this.life+" Size: "+ this.size+" Health: "+ this.health; return str; }

// ------Setters--------- public void setAttackStrength(int attackStrength) { this.attackStrength = attackStrength; } public void setBoss(boolean boss) { this.boss = boss; } public void setLife(boolean life) { this.life = life; } public void setSize(int size) { this.size = size; } public void setHealth(int health) { this.health = health; } // ------Getters--------- public int getAttackStrength() { return attackStrength; } public boolean isBoss() { return boss; } public boolean getLife() { return life; } public int getSize() { return size; } public int getHealth() { return health; } }

Zombie.java

public class Zombie { Creature cre=new Creature(false); Weapon wea=new Weapon("None"); private String zombieType; private String zombieWeakness; private Weapon zombieWeapon; static private String [] weapons = {"Cricket Bat", "None", "None"}; 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)]); this.setZombieWeapon(wea = new Weapon((weapons[random(0, weapons.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, Weapon wNa ){ this.setZombieType(zTyp); this.setZombieWeakness(zWeak); this.setZombieWeapon(wNa); } @Override public String toString() { String str="Zombie Type: "+ this.zombieType+" Zombie Weakness: "+ this.zombieWeakness+" Zombie Weapon: "+ this.zombieWeapon; return str; } public int attack() { int attackIndex = 0; String Weapon = "Cricket Bat"; for (int i = 0; i

Hunter.java

public class Hunter { Weapon wea=new Weapon("None"); private String name; private boolean life; private Weapon leftHandWeapon; private Weapon rightHandWeapon; private double attackStrength; private int health; static private String [] attackType = {"Intelligence", "Speed", "Fire"}; private int coins; //constructor public Hunter(String name) { this.setName(name); this.setLife(true); this.setLeftHandWeapon(wea = new Weapon("Bat")); this.setRightHandWeapon(wea = new Weapon("Sword")); this.setAttackStrength(1); this.setHealth(50); this.setCoins(0); } public Hunter(String na, boolean lif, Weapon lWeap, Weapon rWeap, double attSt, int hth, int co){ this.setName(na); this.setLife(lif); this.setLeftHandWeapon(lWeap); this.setRightHandWeapon(rWeap); this.setAttackStrength(attSt); this.setHealth(hth); this.setCoins(co); } @Override public String toString() { String str="Name: "+ this.name+" Life: "+ this.life+" Left Hand Weapon: "+ this.leftHandWeapon+" Right Hand Weapon: "+ this.rightHandWeapon+" Attack Strength: "+ this.attackStrength+" Health: "+ this.health+" Coins: "+ this.coins; return str; } // Setters public void setName(String name) { this.name = name; } public void setLife(boolean life) { this.life = life; } public void setLeftHandWeapon(Weapon leftHandWeapon) { this.leftHandWeapon = leftHandWeapon; } public void setRightHandWeapon(Weapon rightHandWeapon) { this.rightHandWeapon = rightHandWeapon; } public void setAttackStrength(double attackStrength) { this.attackStrength = attackStrength; } public void setHealth(int health) { this.health = health; } public void setCoins(int coins) { this.coins = coins; } // Getters

public String getName() { return name; } public boolean getLife() { return life; } public Weapon getLeftHandWeapon() { return leftHandWeapon; } public Weapon getRightHandWeapon() { return rightHandWeapon; } public double getAttackStrength() { return attackStrength; } public int getHealth() { return health; } public int getCoins() { return coins; } }

Weapon.java

size; private int health; // Constructor public Creature(boolean boss) { // creature

I have to put some as image in order to make this question.

PART 1 Create Hunter Object. The UML below shows the Hunter Class: Hunter Name: String life: bool leftHandWeapon: weapon rightHandWeapon: weapon attackStrength: double health: int attackType: string II coins: int + Hunter() + setAttackStrength (double): void + setLife(bool): void + setHealth(int): void + setCoin(int): void + getAttackStrength ():double + getLife (): bool + getHealth():int + getCoin(): int + hunterAttack(Creature): int + hunterGetAttacked(Creature): int + toString(): String Let's setup some rules; you must use the setters when creating a Hunter object (using the constructor), you should know that the data members works together: The user (player) should give the hunter a cool name of his/her choice. The health will be set to 50 initially. The life data member should be set to true. The coin should be set to 0 initially. The attackStrenth should be set to 1. The attackType static array should be populated with the following data: "Intelligence"," Speed", and "Fire", PART 2 With every hunterAttack call and after performing the attack, you will need to check the life of the creature object, if the creature is dead (life == false), the data member of the hunter object will be updated as following: The hunter will gain 2 coins. If the coins data member was dividable by 10: the health will be increased by 2, and attackStrenth will be increased by 0.2. Since the Hunter will be using a weapon, we need to update the Weapon class. If the passed string of the weapon constructor is leftHandHunter, the weapon Name should be set to "Gun. If the passed string is rightHandHunter, the weapon Name should be set to "One-Handed Axes". Make sure to pass the correct string argument. Let's go back to the hunterAttack method, when the hunter attacks, the creature will get attacked (duh). This is where we have to go back to each one of the creature classes to update and implement the getAttacked methods. The method should be redefined as following: public boolean getAttacked(double hunterAttackStrength, String weakness, int hunterWeaponStrength) The health of the creature will be decreased when the method getAttacked is called as following: If the passed weakness match the creature weakness: health-health-(2* hunterWeaponStrength*hunterAttackStrength) Otherwise health=health - (hunterWeaponStrength*hunterAttackStrength) Note: you should cast the hunterAttackStrength to integer since the health of the creature is an integer data member. PART 3 Right after updating the health of the creature, you should check if the health equal zero or less than zero (-value). In this case, the life of the creature should be changed to false and returned. Now that we completed the getAttacked method for the Zombie Class it's time to go back to the hunterAttack method. The user (hunter) should decide what will be the weakness that he/she will attack and which hand he/she will be used. After that the getAttacked method should be called. Remember the getAttack method is a non-static method, so it should be associated with a creature, which you wish to attack (it will be passed as a parameter). Use the return Boolean variable to decide weather the hunter data members will be updated as explained previously. The hunterGetAttacked method works similar to the hunterAttack method. Inside the body of hunterGetAttacked, call the attack method the creature object. Use the returned integer to update the hunter health: hunter health=hunter health returned value of creature attack method All what is left is to implement the toString method Inside the main method, create a Hunter Object and test the attack method and get attack method of the hunter object using the creatures you created early. 3 4. E 7 8 160 1 public class Weapon { 2 private String weaponName; private int weaponStrength; //constructor 60 public Weapon(String weaponName) { // Weapon Strength from 1 to 3 int min = 1, max - 3; 10 11 this.setWeaponName(weaponName); 12 this.setWeaponStrength(random(min, max)); 13 } 14 15 // Generates random values between given range private int random(int min, int max) { 17 return (int) (Math.random() (max min + 1) + min); 18 } 19 200 public Weapon(String wNa, int wstr ) { 21 this.setWeaponName(wNa);| 22 this.setWeaponStrength(wStr); 23 } 24 250 @Override 26 public String toString() { 27 String str=this.weaponName+" Weapon Strength: "+this.weaponStrength; 28 return str; 29 } 30 31 // Setters 320 public void setWeaponName(String weaponName) { 33 this.weaponName = weaponName; 34 } 350 public void setWeaponStrength(int weaponStrength) { 36 this.weaponStrength = weaponStrength; 37 } 38 39 // Getters 400 public String getWeaponName() { 41 return weaponName; 42 } 430 public int getWeaponStrength() { 44 return weaponStrength; 45 } 46 3 5 6 7 9 10 i public class MainClass { 20 public static void main(String[] args) { Creature [] cre=new Creature[2]; 4 Hunter [] hun=new Hunter[1]; Zombie () zom=new Zombie[2]; zom[@]=new Zombie(); 8 cre[@]=new Creature(false); zom[1]=new Zombie(); cre[1]=new Creature(true); 11 hun[@]=new Hunter("Jonny"); 12 13 System.out.println("- -"); 14 System.out.println("HUNTER "thun[0]);|| 15 System.out.println("-- -"); 16 17 System.out.println("Zombie 1 "+zom[@]+" "+cre[@]); 18 System.out.println("- --"); 19 System.out.println("Zombie 2 "+zom[1]+" "+cre[1]); 20 21 System.out.print("Creature attacked Hunter! "); 22 zom[0].attack(); 23 } 24 } PART 1 Create Hunter Object. The UML below shows the Hunter Class: Hunter Name: String life: bool leftHandWeapon: weapon rightHandWeapon: weapon attackStrength: double health: int attackType: string II coins: int + Hunter() + setAttackStrength (double): void + setLife(bool): void + setHealth(int): void + setCoin(int): void + getAttackStrength ():double + getLife (): bool + getHealth():int + getCoin(): int + hunterAttack(Creature): int + hunterGetAttacked(Creature): int + toString(): String Let's setup some rules; you must use the setters when creating a Hunter object (using the constructor), you should know that the data members works together: The user (player) should give the hunter a cool name of his/her choice. The health will be set to 50 initially. The life data member should be set to true. The coin should be set to 0 initially. The attackStrenth should be set to 1. The attackType static array should be populated with the following data: "Intelligence"," Speed", and "Fire", PART 2 With every hunterAttack call and after performing the attack, you will need to check the life of the creature object, if the creature is dead (life == false), the data member of the hunter object will be updated as following: The hunter will gain 2 coins. If the coins data member was dividable by 10: the health will be increased by 2, and attackStrenth will be increased by 0.2. Since the Hunter will be using a weapon, we need to update the Weapon class. If the passed string of the weapon constructor is leftHandHunter, the weapon Name should be set to "Gun. If the passed string is rightHandHunter, the weapon Name should be set to "One-Handed Axes". Make sure to pass the correct string argument. Let's go back to the hunterAttack method, when the hunter attacks, the creature will get attacked (duh). This is where we have to go back to each one of the creature classes to update and implement the getAttacked methods. The method should be redefined as following: public boolean getAttacked(double hunterAttackStrength, String weakness, int hunterWeaponStrength) The health of the creature will be decreased when the method getAttacked is called as following: If the passed weakness match the creature weakness: health-health-(2* hunterWeaponStrength*hunterAttackStrength) Otherwise health=health - (hunterWeaponStrength*hunterAttackStrength) Note: you should cast the hunterAttackStrength to integer since the health of the creature is an integer data member. PART 3 Right after updating the health of the creature, you should check if the health equal zero or less than zero (-value). In this case, the life of the creature should be changed to false and returned. Now that we completed the getAttacked method for the Zombie Class it's time to go back to the hunterAttack method. The user (hunter) should decide what will be the weakness that he/she will attack and which hand he/she will be used. After that the getAttacked method should be called. Remember the getAttack method is a non-static method, so it should be associated with a creature, which you wish to attack (it will be passed as a parameter). Use the return Boolean variable to decide weather the hunter data members will be updated as explained previously. The hunterGetAttacked method works similar to the hunterAttack method. Inside the body of hunterGetAttacked, call the attack method the creature object. Use the returned integer to update the hunter health: hunter health=hunter health returned value of creature attack method All what is left is to implement the toString method Inside the main method, create a Hunter Object and test the attack method and get attack method of the hunter object using the creatures you created early. 3 4. E 7 8 160 1 public class Weapon { 2 private String weaponName; private int weaponStrength; //constructor 60 public Weapon(String weaponName) { // Weapon Strength from 1 to 3 int min = 1, max - 3; 10 11 this.setWeaponName(weaponName); 12 this.setWeaponStrength(random(min, max)); 13 } 14 15 // Generates random values between given range private int random(int min, int max) { 17 return (int) (Math.random() (max min + 1) + min); 18 } 19 200 public Weapon(String wNa, int wstr ) { 21 this.setWeaponName(wNa);| 22 this.setWeaponStrength(wStr); 23 } 24 250 @Override 26 public String toString() { 27 String str=this.weaponName+" Weapon Strength: "+this.weaponStrength; 28 return str; 29 } 30 31 // Setters 320 public void setWeaponName(String weaponName) { 33 this.weaponName = weaponName; 34 } 350 public void setWeaponStrength(int weaponStrength) { 36 this.weaponStrength = weaponStrength; 37 } 38 39 // Getters 400 public String getWeaponName() { 41 return weaponName; 42 } 430 public int getWeaponStrength() { 44 return weaponStrength; 45 } 46 3 5 6 7 9 10 i public class MainClass { 20 public static void main(String[] args) { Creature [] cre=new Creature[2]; 4 Hunter [] hun=new Hunter[1]; Zombie () zom=new Zombie[2]; zom[@]=new Zombie(); 8 cre[@]=new Creature(false); zom[1]=new Zombie(); cre[1]=new Creature(true); 11 hun[@]=new Hunter("Jonny"); 12 13 System.out.println("- -"); 14 System.out.println("HUNTER "thun[0]);|| 15 System.out.println("-- -"); 16 17 System.out.println("Zombie 1 "+zom[@]+" "+cre[@]); 18 System.out.println("- --"); 19 System.out.println("Zombie 2 "+zom[1]+" "+cre[1]); 20 21 System.out.print("Creature attacked Hunter! "); 22 zom[0].attack(); 23 } 24 }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!