Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: This is first part of the project which is already completed, here are the two files from first part CODE: Main public class Main

JAVA: This is first part of the project

image text in transcribedwhich is already completed, here are the two files from first part

CODE: Main

public class Main { 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]);

}

}

CODE: Creature

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; } }

Can I get help implementing part 2, here are the instructions

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Thanks!

Make sure to override the method toString to return string about the status of the creature. Attack method will be useful when you create your character in next phase (the hunter). For now, the attack method returns an integer which is calculated as following. Attack type: returned integer bite (0+1)*2 =2 fire ball (1+1)*2 =4 You fall asleep after a long day and you had this wired dream about yourself hunting Zombies, Demons, Ghosts, Vampires, Monsters and Witches. It was a scary dream, but it was fun at the same time. You wake up scared and you remembered every detail about the dream. In the dream you were attacked by all these creatures and you were hunting them using a set of weapons you have. Some creatures were stronger than others. Next day, you had the same dream, only this time you started remembering more details. You told your friends about these dreams and everyone told you that you should do something about this. Some suggested to create an RPG (role-playing game) game about these dreams. Again, you kept having more dreams about hunting these creatures most of the nights. You start writing notes about your dreams to use them in the process of creating the game. You decided to use Java to design and implement this game, your first step is to build a class called creature. The following UML (Unified Modeling Language) define the class creature based on the notes you wrote after your last dreams. + setWeakness(String): void + setBoss(bool): void + setLife(bool): void + setSize(int): void + setHealth(int): void + setAttack(String): void + getType():String + getStrength():int + getWeakness():String + getBoss():bool + getLife (): bool + getSize():int + getHealth():int + getAttack():String + toString(): String + attack(): int + attacked(String): void magic Spell (2+1)*2 =6 (3+1)* 2 =8 acid attack spiritual attack (4+1)*2 =10 smash attack (5+1)* 2 =12 creature voodoo. (6+1)*2 =14 note that you can use the array allAttacks to calculate the returned integer. Use the index of the attack (in the allAttacks array) that match the attack of the creature and add one to it, then multiply the results by 2. This returned value will be subtracted from the player health "the hunter (Phase 2, will be explained in Lesson 2). Class description: allWeakness, allAttacks and allCreaters are pre-defined static array of strings. Populate these arrays as following: allCreaters: Zombies, Demons, Ghosts, Vampires, Monsters and Witches type: String strength: int weakness: String boss: bool life: bool size: int health: int attack: String allWeakness: String [] allAttacks: String [] allCreaters: String [] + creature) + setType(String): void + setStrength(int): void allWeakness: garlic, silver, water, holy books, ritual, fire, light. allAttacks: bite, fire ball, magic Spell, acid attack, spiritual attack, smash attack, voodoo. The attacked method will be called when the creature is attacked by the hunter, this method updates the health variable as following: first, check if the creature is a life, if that's not a life, show a message to state that the creature is dead. Otherwise, if the string parameter (presents the attack of the hunter "will be explained in phase 2") match the creature weakness, subtract 10 from the health of the creature. Otherwise, subtract 5. In this method, you need to make sure the health will not be below zero. Whenever the health of the creature gets to zero or below, change the life variable to false and state that the creature is dead. In the default constructor, most of the data members need to be initialized randomly. Make sure to use the setters. Also, use the three static arrays to assign values to type, attack and weakness. The values of strength, size and health should be in the range from 25 to 100. If the creature is a boss, strength, size and health must have the value of 100. Also, life variable should be set to true. Create multiple creatures (5 at least), print their states at the beginning, call the method attacked 4 times for each object creature (2 attacks match the weakness and 2 attacks do not match the weakness of the creature). Print their states after the 4 attacks for each creature. Make sure to save your work because you will use it later in Lesson 2 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. Make sure to override the method toString to return string about the status of the creature. Attack method will be useful when you create your character in next phase (the hunter). For now, the attack method returns an integer which is calculated as following. Attack type: returned integer bite (0+1)*2 =2 fire ball (1+1)*2 =4 You fall asleep after a long day and you had this wired dream about yourself hunting Zombies, Demons, Ghosts, Vampires, Monsters and Witches. It was a scary dream, but it was fun at the same time. You wake up scared and you remembered every detail about the dream. In the dream you were attacked by all these creatures and you were hunting them using a set of weapons you have. Some creatures were stronger than others. Next day, you had the same dream, only this time you started remembering more details. You told your friends about these dreams and everyone told you that you should do something about this. Some suggested to create an RPG (role-playing game) game about these dreams. Again, you kept having more dreams about hunting these creatures most of the nights. You start writing notes about your dreams to use them in the process of creating the game. You decided to use Java to design and implement this game, your first step is to build a class called creature. The following UML (Unified Modeling Language) define the class creature based on the notes you wrote after your last dreams. + setWeakness(String): void + setBoss(bool): void + setLife(bool): void + setSize(int): void + setHealth(int): void + setAttack(String): void + getType():String + getStrength():int + getWeakness():String + getBoss():bool + getLife (): bool + getSize():int + getHealth():int + getAttack():String + toString(): String + attack(): int + attacked(String): void magic Spell (2+1)*2 =6 (3+1)* 2 =8 acid attack spiritual attack (4+1)*2 =10 smash attack (5+1)* 2 =12 creature voodoo. (6+1)*2 =14 note that you can use the array allAttacks to calculate the returned integer. Use the index of the attack (in the allAttacks array) that match the attack of the creature and add one to it, then multiply the results by 2. This returned value will be subtracted from the player health "the hunter (Phase 2, will be explained in Lesson 2). Class description: allWeakness, allAttacks and allCreaters are pre-defined static array of strings. Populate these arrays as following: allCreaters: Zombies, Demons, Ghosts, Vampires, Monsters and Witches type: String strength: int weakness: String boss: bool life: bool size: int health: int attack: String allWeakness: String [] allAttacks: String [] allCreaters: String [] + creature) + setType(String): void + setStrength(int): void allWeakness: garlic, silver, water, holy books, ritual, fire, light. allAttacks: bite, fire ball, magic Spell, acid attack, spiritual attack, smash attack, voodoo. The attacked method will be called when the creature is attacked by the hunter, this method updates the health variable as following: first, check if the creature is a life, if that's not a life, show a message to state that the creature is dead. Otherwise, if the string parameter (presents the attack of the hunter "will be explained in phase 2") match the creature weakness, subtract 10 from the health of the creature. Otherwise, subtract 5. In this method, you need to make sure the health will not be below zero. Whenever the health of the creature gets to zero or below, change the life variable to false and state that the creature is dead. In the default constructor, most of the data members need to be initialized randomly. Make sure to use the setters. Also, use the three static arrays to assign values to type, attack and weakness. The values of strength, size and health should be in the range from 25 to 100. If the creature is a boss, strength, size and health must have the value of 100. Also, life variable should be set to true. Create multiple creatures (5 at least), print their states at the beginning, call the method attacked 4 times for each object creature (2 attacks match the weakness and 2 attacks do not match the weakness of the creature). Print their states after the 4 attacks for each creature. Make sure to save your work because you will use it later in Lesson 2 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

Big Data With Hadoop MapReduce A Classroom Approach

Authors: Rathinaraja Jeyaraj ,Ganeshkumar Pugalendhi ,Anand Paul

1st Edition

1774634848, 978-1774634844

More Books

Students also viewed these Databases questions

Question

Value preferred stock.

Answered: 1 week ago