Java code as instructed and also follow the import restrictions on page 2.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please write Java code as instructed and also follow the import restrictions on page 2. Thank you!

Problem Description
Water. Earth. Fire. Air. While the Avatar cyclehas seemingly nded, the 4mations are preparing for war and it is up
to you, fellow 1331 student, to halp determine who will win! As cach nation gathers thair armies, the fire nation
decides to attack the 3 ather nations, forcing the remaining 3 to ally with cach other. Asall th nazions summon
heroesto help them defeat the anemy, and you will hava to write a program to determine which army has the
strongest support from their haroes.
Your assignment will consist of 2 main parts
Determining how many haroes ara summoned, which nzion thay belong to and what statistics they have.
Printing out the haroinformation and averaging it out for the hero's kingdom to see who wins.
Some notes for all variables in the assignment:
When askad to generats a random variable, you must us java.util.Random
L When askad to generate a ficating-point valus, round the value to 2 decimal plsces. You can only use
Math.round () to raund the valus, butremamber thz you have operators liks.-.and / to halp you
achieve proper rounding
L
Solution Description
1. Create a public enum called BendingType
a This special class should be defined in a ats file.
2. Populate the enum with the valuas AIR, GATER, FIRE, EARIH, NON_BENDER.
3. Create a public class calisd BendingBattlefield
4. Creats thsain method
5. Insida, creats the following variables
An instance of Random named rand.
b. An int called mumierces and asign toita random valus in the range (50, 1001.
.. A double calld boomerangBoost and assign to it arandom valus in the range (3, 7).
Note the interval notation
[a, b] means anumber xsuch that a 1 b.
(2, b] means a number x such tha < I b.
[2, b) means a number xsuch that a x< b.
(2, b) means a number x such tha < I< b.
6. Create four double variables: avezagefireFovez, zveragefirelealth,
averageallianceForer, and averagealliancelealth.
7. Print mumieroes with the following format
"Selecting <numHeroes> heroes."
8. Creats an int named nfire that will izsparunning total of the number of herossbelonging to the
FIRE nation.
9. Create an int named mumalliance that will lesparunning total of the number of heroes belonging to
the AIR, MATER, EARTH, or NCN_BENDER nations.
10. Create a loop that terminatas aftar numlerces iterations. Performsteps 11 to 17 inside the loop.
Transcribed Image Text:Problem Description Water. Earth. Fire. Air. While the Avatar cyclehas seemingly nded, the 4mations are preparing for war and it is up to you, fellow 1331 student, to halp determine who will win! As cach nation gathers thair armies, the fire nation decides to attack the 3 ather nations, forcing the remaining 3 to ally with cach other. Asall th nazions summon heroesto help them defeat the anemy, and you will hava to write a program to determine which army has the strongest support from their haroes. Your assignment will consist of 2 main parts Determining how many haroes ara summoned, which nzion thay belong to and what statistics they have. Printing out the haroinformation and averaging it out for the hero's kingdom to see who wins. Some notes for all variables in the assignment: When askad to generats a random variable, you must us java.util.Random L When askad to generate a ficating-point valus, round the value to 2 decimal plsces. You can only use Math.round () to raund the valus, butremamber thz you have operators liks.-.and / to halp you achieve proper rounding L Solution Description 1. Create a public enum called BendingType a This special class should be defined in a ats file. 2. Populate the enum with the valuas AIR, GATER, FIRE, EARIH, NON_BENDER. 3. Create a public class calisd BendingBattlefield 4. Creats thsain method 5. Insida, creats the following variables An instance of Random named rand. b. An int called mumierces and asign toita random valus in the range (50, 1001. .. A double calld boomerangBoost and assign to it arandom valus in the range (3, 7). Note the interval notation [a, b] means anumber xsuch that a 1 b. (2, b] means a number x such tha < I b. [2, b) means a number xsuch that a x< b. (2, b) means a number x such tha < I< b. 6. Create four double variables: avezagefireFovez, zveragefirelealth, averageallianceForer, and averagealliancelealth. 7. Print mumieroes with the following format "Selecting <numHeroes> heroes." 8. Creats an int named nfire that will izsparunning total of the number of herossbelonging to the FIRE nation. 9. Create an int named mumalliance that will lesparunning total of the number of heroes belonging to the AIR, MATER, EARTH, or NCN_BENDER nations. 10. Create a loop that terminatas aftar numlerces iterations. Performsteps 11 to 17 inside the loop.
11. Create a local BendingType variable called heroIype and assign a random BendingType to it.
a.
You can do this using this line:
BendingType heroType
= BendingType.values () [rand.nextInt (5)1;
12. Create a double variable called health and assign a random value in the range (50, 150).
Make sure all your floating-point values are rounded to 2 decimal places using Math.round ().
a.
13. Create a double variable called power and assign a random value in the range (40, 120] to it.
a.
Make sure all your floating-point values are rounded to 2 decimal places using Math.round ().
14. If the heroType is FIRE, then health and power will be added to averageFireHealth and
averageFirePower, respectively. Increment numFire appropriately.
15. If heroType is NON_BENDER, multiply power by boomerangBoost.
16. If the heroType is NON_BENDER, AIR, WATER, or EARTH, then health and power will be added to
averageAlliancelealth and averageAlliancePower, respectively. Increment
numAlliance appropriately.
17. Print the status of the hero. You can follow the following format
"<heroType> hero has been summoned by his army, adding <power> power
and <health> health to the army."
18. Once the loop has completed, divide each of the averages, averageFirePower,
averageFireHealth, averageAlliancePower, and averageAllianceHealth by their total
number of respective heroes, numFire or numAlliance, to get the correctaverage.
19. Print out the following statistics:
"The Fire Nation has an average of <averageFirePower> power and
a.
<averageFireHealth> health."
b.
"The Alliance has an average of <averageAlliancePower> power and
<averageAllianceHealth> health."
20. Calculate whether the Fire nation or the Alliance won by comparing 2 - averagePower + 3 -
averageHealth of each side and checking which one is larger, If they are equal, then the Alliance wins.
a.
If the Fire Nation won, print
"The Fire Nation won!"
b.
else if the Alliance won, print
S1331
"The Alliance won!"
Example Outputs
Please refer to the PE clarification thread on Ed for examples.
HINT: To help debug your code, try inserting print statements in ploces where variables are changed.
Feature Restrictions
There are a few features and methods in Java that overiysimplify the concepts we are trying to teach or break our
auto grader. For that reason, do not use any of the following in your final submission:
var (the reserved keyword)
System.exit
Import Restrictions
You can import only the following classes:
java.util.Random
Transcribed Image Text:11. Create a local BendingType variable called heroIype and assign a random BendingType to it. a. You can do this using this line: BendingType heroType = BendingType.values () [rand.nextInt (5)1; 12. Create a double variable called health and assign a random value in the range (50, 150). Make sure all your floating-point values are rounded to 2 decimal places using Math.round (). a. 13. Create a double variable called power and assign a random value in the range (40, 120] to it. a. Make sure all your floating-point values are rounded to 2 decimal places using Math.round (). 14. If the heroType is FIRE, then health and power will be added to averageFireHealth and averageFirePower, respectively. Increment numFire appropriately. 15. If heroType is NON_BENDER, multiply power by boomerangBoost. 16. If the heroType is NON_BENDER, AIR, WATER, or EARTH, then health and power will be added to averageAlliancelealth and averageAlliancePower, respectively. Increment numAlliance appropriately. 17. Print the status of the hero. You can follow the following format "<heroType> hero has been summoned by his army, adding <power> power and <health> health to the army." 18. Once the loop has completed, divide each of the averages, averageFirePower, averageFireHealth, averageAlliancePower, and averageAllianceHealth by their total number of respective heroes, numFire or numAlliance, to get the correctaverage. 19. Print out the following statistics: "The Fire Nation has an average of <averageFirePower> power and a. <averageFireHealth> health." b. "The Alliance has an average of <averageAlliancePower> power and <averageAllianceHealth> health." 20. Calculate whether the Fire nation or the Alliance won by comparing 2 - averagePower + 3 - averageHealth of each side and checking which one is larger, If they are equal, then the Alliance wins. a. If the Fire Nation won, print "The Fire Nation won!" b. else if the Alliance won, print S1331 "The Alliance won!" Example Outputs Please refer to the PE clarification thread on Ed for examples. HINT: To help debug your code, try inserting print statements in ploces where variables are changed. Feature Restrictions There are a few features and methods in Java that overiysimplify the concepts we are trying to teach or break our auto grader. For that reason, do not use any of the following in your final submission: var (the reserved keyword) System.exit Import Restrictions You can import only the following classes: java.util.Random
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY