Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my current code, now I need help implementing what is shown in the pictures CODE: public class MainClass { public static void main(String[]

This is my current code, now I need help implementing what is shown in the pictures

CODE:

public class MainClass { public static void main(String[] args) { // TODO Auto-generated method stub Creature [] cre=new Creature[5]; cre[0]=new Creature(true); cre[1]=new Creature(false); cre[2]=new Creature(false); cre[3]=new Creature(true); cre[4]=new Creature(false);

System.out.println("Creature 1 "+cre[0]); System.out.println("-----------------------"); System.out.println("Creature 2 "+cre[1]); System.out.println("-----------------------"); System.out.println("Creature 3 "+cre[2]); System.out.println("-----------------------"); System.out.println("Creature 4 "+cre[3]); System.out.println("-----------------------"); System.out.println("Creature 5 "+cre[4]); System.out.println(" "); // Creature being attacked System.out.println(" ");

cre[0].attacked("water"); cre[0].attacked("silver"); cre[0].attacked("water"); cre[0].attacked("holy books");

cre[1].attacked("ritual"); cre[1].attacked("fire"); cre[1].attacked("light"); cre[1].attacked("fire");

cre[2].attacked("garlic"); cre[2].attacked("water"); cre[2].attacked("light"); cre[2].attacked("garlic");

cre[3].attacked("fire"); cre[3].attacked("ritual"); cre[3].attacked("fire"); cre[3].attacked("water");

cre[4].attacked("ritual"); cre[4].attacked("silver"); cre[4].attacked("holy books"); cre[4].attacked("silver"); System.out.println(""); System.out.println("Creature 1 "+cre[0]); System.out.println("-----------------------"); System.out.println("Creature 2 "+cre[1]); System.out.println("-----------------------"); System.out.println("Creature 3 "+cre[2]); System.out.println("-----------------------"); System.out.println("Creature 4 "+cre[3]); System.out.println("-----------------------"); System.out.println("Creature 5 "+cre[4]);

}

}

Second file of the code:

public class Creature { private String type; private int strength; private String weakness; private boolean boss; private boolean life; private int size; private int health; private String attack; static private String [] allWeakness = {"garlic", "silver", "water", "holy books", "ritual", "fire", "light"}; static private String [] allAttacks = {"bite", "fire ball", "magic spell", "acid attack", "spiritual attack", "smash attack", "voodoo"}; static private String [] allCreatures = {"Zombies", "Demons", "Ghosts", "Vampires", "Monsters", "Witches"}; // Constructor public Creature(boolean boss) { // creature ranges from 25 to 100 int min = 25, max = 100; // if boss, states equal 100 if(boss) { min = 100; max = 100; } // creature generating randomly this.setType(allCreatures[random(0, allCreatures.length - 1)]); this.setStrength(random(min, max)); this.setWeakness(allWeakness[random(0, allWeakness.length - 1)]); this.setBoss(boss); this.setLife(true); this.setSize(random(min, max)); this.setHealth(random(min, max)); this.setAttack(allAttacks[random(0, allAttacks.length - 1)]); } // Generates random values between given range private int random(int min, int max) { return (int) (Math.random() * (max - min + 1) + min); } public Creature(String ty, int stre , String wk, boolean boss, boolean life, int siz, int hth, String att){ this.setType(ty); this.setStrength(stre); this.setWeakness(wk); this.setBoss(boss); this.setLife(life); this.setSize(siz); this.setHealth(hth); this.setAttack(att); } @Override public String toString() { String str="Type: "+ this.type+" Strength: "+ this.strength+" Weakness: "+ this.weakness+" Boss: "+ this.boss+" Life: "+ this.life+" Size: "+ this.size+" Health: "+ this.health+" Attack: "+ this.attack; return str; } public int attack() { int attackIndex = 0; for (int i = 0; i

} else { // If not a life then show message System.out.println(this.type +" died!"); } } // ------Setters--------- public void setType(String type) { this.type = type; } public void setStrength(int strength) { this.strength = strength; } public void setWeakness(String weakness) { this.weakness = weakness; } 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; } public void setAttack(String attack) { this.attack = attack; } // ------Getters--------- public String getType() { return type; } public int getStrength() { return strength; } public String getWeakness() { return weakness; } public boolean isBoss() { return boss; } public boolean getLife() { return life; } public int getSize() { return size; } public int getHealth() { return health; } public String getAttack() { return attack; } }

===================================================================

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

I believed that I included everything, constructor is there, there are two codes each, MainClass file and Creature file

Right after you completed the design and implementation of the creature class, you realized that the method of having all the creatures defined under one class doesn't make since and it will lead to a lot of complication in the future when more details will be added to the game. So, you decided to update the creature class as following: Creature attackStrength: int boss: bool life: bool size: int health: int + creature) + creature(int, bool, int, int) + setAttackStrength (int): void + setBoss(bool): void + setLife(bool): void + setSize(int): void + setHealth(int): void + getType():String + getAttackStrength ():int + getBoss():bool + getLife (): bool + getSize():int + getHealth():int + toString(): String No changed will be applied to most of attributes and methods listed in the UML of the creature class except deleting some private and public members (Check the UML of Lesson 1). The strength data member is replaced by attackStrength. The random value which will be used to set attackStrength will be in the range 1 to 3. Also, if the creature is a boss, attackStrength should be set to 3. Remember, the default constructor will set the data members to random default values within the range described in the previous phase (Project 1). The setters parameter values will be accepted as long as they are within the default range. If the values are not within the default range, set the value randomly using the same range. You also decided to create new 4 classes to inherit form creature class, the 4 classes are: Zombie, Vampire, Monster, and Witch. The classes are described as shown below in the UMLS. Zombie zombieType: String zombies: String Il zombieWeakness: String weaknesses: String Il Vampire vampireType: String vampires: String [1 vampireWeakness: String weaknesses: String 1 zombieWeapon: weapon vampire Weapon: weapon + + + + + + + + Zombiel) Zombie(String) setZombieType(String):void setZombieWeakness(String): void getZombieWeakness(): String getZombieType():String attack():int getAttacked():void toString(): String vampire (1) vampire (String) setVampireType(String):void setVampireWeakness(String): void getVampireWeakness (): String getVampireType():String attack():int getAttacked():void + + + + + + + + + + toString(): String Monster Witch monsterType: String monsters: String 11 monsterWeakness: String weaknesses: String II monsterWeapon: weapon + + + + witchType: String witches: String 1 witcheWeakness: String weaknesses: String [1 witchWeapon: weapon Witch() Witch(String) setWitchType(String):void setWitchWeakness(String): void getWitch Weaknesss(): String getWitchType():String attack():int getAttacked():void toString(): String + + Monster() Monster(String) setMonsterType(String):void setMonsterWeakness(String): void getMonsterWeaknesss(): String getMonsterType():String attack():int + + + + + + + + + + getAttacked():void toString(): String + + The 4 classes are very similar, I will explain the class zombie and you should apply what you will understand on the other 3 classes. But before that, let's talk about the static arrays. For each class, the static arrays must be populated as following: Zombie: zombies={" Chemical, Radiation", "Parasite"} weaknesses={"Intelligence","Speed", "Fire"} Vampire: vampires={"Sanguinarian", "Psychic, Hybrids"} weaknesses={"Fire", "Garlic", "Sunlight" } Monster: monsters={"Werewolves", "Lamia", "Dragons"} weaknesses={ Thunder", "ice", "Paralysis"} Witch: witches={"Cosmic, Magical, Shamanic"} weaknesses={"Salt, Vocalization", "Visual"} when creating a zombie object, the type should be one of the zombies listed in the static array "zombies. In the default constructor, a random one should be chosen. In the argument constructor, if the parameter doesn't match one of the zombies in the array "zombies, the first element in the array should be assigned to the type. Same mechanize should be applied to the zombieWeakness, use the static array"weaknesses" to complete this part. 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". Test your game by creating 4 objects (Zombie, Vampire, Monster, and a Witch) using the default constructor. Print the status of each object. And try the attack method. Run the program 4 times to make sure the program will randomly generate all attributes of the four objects each time you run the program. In the next phase, you will create the hunter class and make the hunter interact with the creatures. You will also implement the method getAttacked. Right after you completed the design and implementation of the creature class, you realized that the method of having all the creatures defined under one class doesn't make since and it will lead to a lot of complication in the future when more details will be added to the game. So, you decided to update the creature class as following: Creature attackStrength: int boss: bool life: bool size: int health: int + creature) + creature(int, bool, int, int) + setAttackStrength (int): void + setBoss(bool): void + setLife(bool): void + setSize(int): void + setHealth(int): void + getType():String + getAttackStrength ():int + getBoss():bool + getLife (): bool + getSize():int + getHealth():int + toString(): String No changed will be applied to most of attributes and methods listed in the UML of the creature class except deleting some private and public members (Check the UML of Lesson 1). The strength data member is replaced by attackStrength. The random value which will be used to set attackStrength will be in the range 1 to 3. Also, if the creature is a boss, attackStrength should be set to 3. Remember, the default constructor will set the data members to random default values within the range described in the previous phase (Project 1). The setters parameter values will be accepted as long as they are within the default range. If the values are not within the default range, set the value randomly using the same range. You also decided to create new 4 classes to inherit form creature class, the 4 classes are: Zombie, Vampire, Monster, and Witch. The classes are described as shown below in the UMLS. Zombie zombieType: String zombies: String Il zombieWeakness: String weaknesses: String Il Vampire vampireType: String vampires: String [1 vampireWeakness: String weaknesses: String 1 zombieWeapon: weapon vampire Weapon: weapon + + + + + + + + Zombiel) Zombie(String) setZombieType(String):void setZombieWeakness(String): void getZombieWeakness(): String getZombieType():String attack():int getAttacked():void toString(): String vampire (1) vampire (String) setVampireType(String):void setVampireWeakness(String): void getVampireWeakness (): String getVampireType():String attack():int getAttacked():void + + + + + + + + + + toString(): String Monster Witch monsterType: String monsters: String 11 monsterWeakness: String weaknesses: String II monsterWeapon: weapon + + + + witchType: String witches: String 1 witcheWeakness: String weaknesses: String [1 witchWeapon: weapon Witch() Witch(String) setWitchType(String):void setWitchWeakness(String): void getWitch Weaknesss(): String getWitchType():String attack():int getAttacked():void toString(): String + + Monster() Monster(String) setMonsterType(String):void setMonsterWeakness(String): void getMonsterWeaknesss(): String getMonsterType():String attack():int + + + + + + + + + + getAttacked():void toString(): String + + The 4 classes are very similar, I will explain the class zombie and you should apply what you will understand on the other 3 classes. But before that, let's talk about the static arrays. For each class, the static arrays must be populated as following: Zombie: zombies={" Chemical, Radiation", "Parasite"} weaknesses={"Intelligence","Speed", "Fire"} Vampire: vampires={"Sanguinarian", "Psychic, Hybrids"} weaknesses={"Fire", "Garlic", "Sunlight" } Monster: monsters={"Werewolves", "Lamia", "Dragons"} weaknesses={ Thunder", "ice", "Paralysis"} Witch: witches={"Cosmic, Magical, Shamanic"} weaknesses={"Salt, Vocalization", "Visual"} when creating a zombie object, the type should be one of the zombies listed in the static array "zombies. In the default constructor, a random one should be chosen. In the argument constructor, if the parameter doesn't match one of the zombies in the array "zombies, the first element in the array should be assigned to the type. Same mechanize should be applied to the zombieWeakness, use the static array"weaknesses" to complete this part. 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". Test your game by creating 4 objects (Zombie, Vampire, Monster, and a Witch) using the default constructor. Print the status of each object. And try the attack method. Run the program 4 times to make sure the program will randomly generate all attributes of the four objects each time you run the program. In the next phase, you will create the hunter class and make the hunter interact with the creatures. You will also implement the method getAttacked

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

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions

Question

6. Identify characteristics of whiteness.

Answered: 1 week ago

Question

9. Explain the relationship between identity and communication.

Answered: 1 week ago