Question

HIGHEST SUBMISSION Vlew All Submissions Submission 17 Submitted on 6/10/2019 12 35 PM by Jenna Saleh DESCRIPTION Objectives T
Create a new project for this battle of Monsters and copy your Monster class from the lab over to this project. Then create t
class.mimir.io/projects/cef81a65-5102-4b58-a7a7-7d6e2b35a8d8 The Battle Using these classes, you should simulate a Battle. A
tps://class.mimir.io/projects/cef81a65-5102-4b58-a7a7-7d6e2b35a8d8 Input and Output space): Here is a sample run with 2 giant
HIGHEST SUBMISSION Vlew All Submissions Submission 17 Submitted on 6/10/2019 12 35 PM by Jenna Saleh DESCRIPTION Objectives To write a classes based on sets of specifications To write a main class to be used in a multi-class Java program To use inheritance to extend a class (optional, EC) To override methods in subclasses (optional, EC) Groups You may work with a partner on this assignment. A header comment (In every Java file) should include authors (group members) and collaborators (others who provided significant assistance). A collaborator may not write your code for you or allow you to copy or use their own code as a reference Use Mimir's group feature to create a group before submitting (see this pege for directions) Description In this project, you will build off of the Monster class created in your leb As a recap, the Monster class has the following data and methods Data o health: double how much damage it takes to kill the Monster double how much damage the Monster con deal with one attack ostrength: Constructors o Monster()initialize the new Monster with 0 health and 0 strenath. oMonster(newHealth: double, newstrength: double) -initialize the new Monster with the given health and strength Methods o getHealth(): double-return the Monster's health. o getstrength(): double-return the Monster's strength. o setHealth (newHealth: double) set the Monster's health to newHealth o setStrength(newstrength: double) - set the Monster's strength to newStrength, o attack(): double return a random number from 0 to the Monster's strength, representing how much damage the Monster dealt with its attack o takeDamage (damage: double) reduce the Monster's health by the amount of damage taken o isAlive(): boolean-return whether the Monster's health is positive Create a new project for this battle of Monsters and copy your Monster class from the lab over to this project Then create two more classes Giant and Oare that behave nearly the same as the Monster class
Create a new project for this battle of Monsters and copy your Monster class from the lab over to this project. Then create two more classes Giantand Ogre that behave nearly the same as the Monster class. Here are the data and methods for the Giant class .Data health: double - how much damage it takes to kill the Giant strength: double - how much damage the Giant can deal with one attack. Constructors Giant()-initielize the new Giant with 1000 health and 20 strength. Methods o getHealth): double-return the Giant's health. getStrength(): double- return the Giant's strength setHealth (newHealth: double) - set the Giant's health to newHealth. setstrength(newStrength: double) set the Giant's strength to newStrength. o attack(): double Everyone knows that Gieants get weaker as they lose health. So, the attack damage returned is not random (as with Monsters] instead it is [strength health/1000). otakeDamage (damage: double) - reduce the Giant's health by the amount of damage given. oisAlive): boolean return whether the Giant's health is positive. Here are the data and methods for the Ogre class Data health: double - how much damage it takes to kill the Ogre. ostrength: double-how much damage the Ogre can deal with one attack o totalHits: int how many times the Ogre has been attacked Constructors Ogre)-initialize the new Ogre with 100 health and 5 strength. Methods getHealth(): double-return the Ogre's health getStrength(): double-return the Ogre's strength. o setHealth (newHealth: double) set the Ogre's health to newHealth. setStrength(newStrength: double)- set the Ogre's strength to newStrength. attack(): double Unlike Giants, Ogres despise being hit and their strength increases every time they are attacked. So, the attacked damage is not random (as with Monsters] instead it is (strength (totalHits 1) o takeDamage (damage: double)- reduce the Ogre's health by the amount of damage given but also increase the totalHits by 1 isAlive(): boolean -return whether the Ogre's health is positive The Battle Using these classes, you should simulate a Battle. A horde of Giants has attacked an army of Ogres. We wish to determine how many Ogres are needed to defeat the Giants. The battle works as follows 1 The current Giant attacks the current Ogre. 2. If the Ogre dies, the next Ogre steps in to teke its place 3. The current Ogre attacks the current Giant 4, If the Giant dies, the next Giant steps in to take its place (until there are no more Giants left) 5. This process repeats until the last Giant falls. [There are more than enough Ogres in the army.) Input and Output
class.mimir.io/projects/cef81a65-5102-4b58-a7a7-7d6e2b35a8d8 The Battle Using these classes, you should simulate a Battle. A horde of Giants has attacked an army of Ogres. determine how many Ogres are needed to defeat the Giants. The battle works as follows: We wish to 1. The current Giant attacks the current Ogre. 2 If the Ogre dies, the next Ogre steps in to take its pleace 3. The current Ogre attacks the current Giant 4. If the Giant dies, the next Giant steps in to take its place (until there 5. This process repeats until the last Giant falls. [There are more than enough Ogres in the army are no more Giants left). Input and Output The input is just the number of Giants During each round, you should output some information about the battle as well as outputting at the end how many Ogres it took. See the sample input and output below. All double values should be printed with exactly two decimal accuracy e.g. 123.45 Submission/Grading When finished, submit the following file(s Monster.java (if using inheritance for extra credit Giant.java (the Giant class) -see below) Ogre.java (the Ogre class) Battle.java (the Battle contains the main() method) This assignment will be graded by Mimir's automated tests, each test of the Battle class uses a different input and compares your output to the expected output. There are also unit tests to see if the Giant and Ogre classes are implemented correctly (particularly, the attack, takeDamage, and isAlive methods). Although the bulk of the grade will be how well the code handles all of the test cases, 20 points will be based on style. In particular, there are many weys to solve this using simple variables, but I am also interested in how well structured the code is using the supplied classes. Here are some things I will look for 5 points: Does the code use the getter/setter (accessor/mutator] methods to adjust the data fields and the other methods (particularly attack and takeDamage] to manage the battle? 5 points: Is the code well commented with proper header comments and inline comments? 5 points: Did you use good, meaningful method names and variable names? 5 points: Is the code well indented? (Eclipse can do this automatically for youl) Advice The notation in the description is a common way to write methods in pseudocode, but it is (intentionally)] the reverse of Java's syntax In Java, a method's return type is written before the name, and methods that return nothing have a return type of void .Use the advice from the Monster lab as well
tps://class.mimir.io/projects/cef81a65-5102-4b58-a7a7-7d6e2b35a8d8 Input and Output space): Here is a sample run with 2 giants [with parts snipped out to save How many Giants are there? >> 2 Giant 1 attacks Ogre 1 for 28.e0 damage. Ogre 1 has 80.e0 health left. Ogre 1 attacks Giant 1 for 10.e0 damage. Giant 1 has 99e.e0 health left. Giant 1 attacks Ogre 1 for 19.8e damage. Ogre 1 has 60.20 health left. Ogre 1 attacks Giant 1 for 15.ee damage. Giant 1 has 975.00 health left. Giant 1 attacks Ogre 1 for 19.5e damage. Ogre 1 has 40.70 health left. Ogre 1 attacks Giant 1 for 20.ee damage. Giant 1 has 955.ee health left. Giant 1 attacks Ogre 1 for 19.10 damage. Ogre 1 has 21.60 health left. Ogre 1 attacks Giant 1 for 25.ee damage. Giant 1 has 930.80 health left. Giant 1 attacks Ogre 1 for 18.60 damage. Ogre 1 has 3.e0 health left. Ogre 1 attacks Giant 1 for 30.ee damage. Giant 1 has 900.ee health left. Giant 1 attacks Ogre 1 for 18.ee damage. Ogre 1 has died. Ogre 2 attacks Giant 1 for 5.00 damage. Giant 1 has 895.80 health left. Giant 1 attacks Ogre 2 for 17.90 damage. Ogre 2 has 82.10 health left. Ogre 2 attacks Giant 1 for 10.e0 damage.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

This is a really lengthy question so i will answering as much as i can (due to time limit)

First we have to create the monster class.

public class Monster {

double health;

double strength;

public void Monster(){

double health= 0;

double strength =0;

}

public void Monster(double health, double strength){

this.health = health;

this.strength = strength;

}

// Getters - getHealth and getStrength

public double getHealth(){

return health;

}

public double getStrength(){

return strength;

}

//Setter - setHealth and set Strength

public double setHealth(double newHealth){

this.health = newHealth;

return health;

}

public double setStrength(double newStrength){

this.strength = newStrength;

return strength;

}

public double attack(){

return health;

}

public double takeDamage(double damage){

return (health - damage);

}

public boolean isAlive(){

if(health>0)

return true;

else

return false;

}

Comment appropriately where ever it is required. In the class basically we have initialized the the healtha and strength variables which is the data. After that the functions are declared i.e. the getter , setters , attack(), takeDamage(), isAlive().

If you look at the other class like Giant and Ogre these class have almost similar data functions. So thats were the inheritance comes into play. extends keyword is used to inherit from the base class. Using inheritance we can use the data and functions in of the base class class in subclass ( to which it is extended).

Here Monster is the base class and Giant and Ogre are the subclasses of Monster class.

Here is Giant class

public class Giant extends Monster{
  
   public void Giant(){
       health = 1000.0;
       strength = 20.0;
   }
   @Override
   public double attack(){
       return (strength*health/1000);
      
   }

}

We can see that attack function of Giant is different from the base Monster class. So for that we override the attack() method in Giant class . Similarly we can create Ogre class . Here please keep in mind that  there will a extra variable totalHits( int totalHits; ) which has to declared first and also the attack function has to be overridden.

Then comes the main function Battle. This function will contain the main method.

Inside the main function we first the get input ( The number of giants that is going to fight).

For that we can use the scanner function to the input from keyboard.

Scanner s= new Scanner(System.in);

int n = s.nextInt();

the variable n will contain the number of giants. Now we have to loop n times as the giants will all die in the end.

You can use any loop.

For easiness i'm using for loop

for( i =1; i<=n; i ++){

//all the logic of the program goes here

}

We have create an object of Giant and Ogre for simulating the battle.

Giant g = new Giant(); // Creates a giant

similarly create an object of Orge o.

now simulating the battling is basically passing the values.
Orge will continue to fight till the giant die . So we have create another loop inside the for loop

while( g.isAlive ){

}

When a giant attacks an Orge we pass the Giant attackdamage to Orge's Damage.

o.setHealth(o.takeDamage(g.attack()))

similarly when ogre attacks a giant.

when o.isAlive becomes false the ogre die and a new ogre is created.( create a new Ogre object)

This continues till all Giants are dead.

Add the print statements as necessary.

Please let me know if you questions as time is short to answer the question completely. I can explain further.

Add a comment
Know the answer?
Add Answer to:
HIGHEST SUBMISSION Vlew All Submissions Submission 17 Submitted on 6/10/2019 12 35 PM by Jenna Saleh...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT