Calculate the total remaining health of each army

Assignment Help JAVA Programming
Reference no: EM131131957

Programming II Lab 6-Threading and Inheritance

Abstract: This lab is part 3 and the final part of a series of Labs. After this, you will have built a very crude but effective game simulation. It will involve warriors, weapons, armies, and a battlefield.

1. Create a new project, do not use the one from Lab 4
2. Copy all of the code and packages from Lab 4 into this new project.
3. Create one more package called Battle

a. Inside Battle you'll need three classes

i. Battlefield

1. This class should hold both ArmyOne and ArmyTwo
2. Create methods to:

a. Pass in and set each army (an army is an array list of Warriors)
b. Calculate the total remaining health of each army
c. Print out the attack strength of each warrior of each army

3. Is also responsible for having two methods that each specifically have one army attacking the other:

a. They should request the Lock and Unlock so only one can run at a time
b. Does the army attacking have any warriors left whose health is greater than 0?
c. To attack, get a warrior from the army and use its attack strength.
d. Check to see if the army they are attacking has any health left
e. If they do, pick a warrior from that army and attack them:

i. If they have more health than the attack, set the health to the difference. (Hint: you'll need to update the super class warrior and all sub class warriors)
ii. If the attack is greater, set the health to that warrior to zero and continue attacking until that attack is used up.
ii. ArmyOneAttacks thread class, takes a battlefield, count of times to attack, and a sleep delay in the constructor
iii. ArmyTwoAttacks thread class, takes a battlefield, count of times to attack, and a sleep delay in the constructor

4. In your Main class, do the following:

a. Create a battlefield object
b. Using the random generation of warriors create an army of 10 warriors and set that to Army One in the battlefield
c. Using the random generation of warriors create a different army of 5 warriors and set that to Army Two in the battlefield.
d. Create the two threads. Pass in the battlefield object and for count of attacks set each to 20. For ArmyOneAttacks make the sleep delay 3000. For ArmyTwoAttacks make the sleep delay 1000.

5. You will have to put print line statements in various places to produce the output below. It doesn't have to match exactly as we may have different warrior classes but it should be pretty close.

Output should read....
Army One's warriors:

classWarriors.InfantryWarrior who attacks -> 4
classWarriors.CavalryWarrior who attacks -> 8
classWarriors.ArtilleryWarrior who attacks -> 2
classWarriors.InfantryWarrior who attacks -> 4
classWarriors.CavalryWarrior who attacks -> 8
classWarriors.ArtilleryWarrior who attacks -> 2
classWarriors.InfantryWarrior who attacks -> 4
classWarriors.InfantryWarrior who attacks -> 4
classWarriors.CavalryWarrior who attacks -> 8
classWarriors.CavalryWarrior who attacks -> 8

Army One's total health is: 52
Army Two's warriors:

classWarriors.InfantryWarrior who attacks -> 4
classWarriors.CavalryWarrior who attacks -> 8
classWarriors.InfantryWarrior who attacks -> 4
classWarriors.CavalryWarrior who attacks -> 8
classWarriors.ArtilleryWarrior who attacks -> 2

Army Two's total health is: 26
Army One attacks and Army Two has 22 remaining.
Army Two attacks and Army One has 48 remaining.
Army Two attacks and Army One has 44 remaining.
Army Two attacks and Army One has 40 remaining.
Army Two attacks and Army One has 38 remaining.
Army Two attacks and Army One has 36 remaining.
Army Two attacks and Army One has 34 remaining.
Army Two attacks and Army One has 28 remaining.
Army One attacks and Army Two has 14 remaining.
Army Two attacks and Army One has 26 remaining.
Army Two attacks and Army One has 24 remaining.
Army Two attacks and Army One has 20 remaining.
Army Two attacks and Army One has 16 remaining.
Army One attacks and Army Two has 10 remaining.
Army One attacks and Army Two has 6 remaining.
Army Two attacks and Army One has 8 remaining.
Army Two attacks and Army One has 0 remaining.
Army One is defeated!!!!
Army One is dead and has no one left to strike.
Army One is defeated!!!!
Army One is defeated!!!!
Army One is defeated!!!!
Army One is dead and has no one left to strike.
Army One is defeated!!!!
Army One is defeated!!!!
Army One is defeated!!!!

Attachment:- Lab_4.zip

Reference no: EM131131957

Questions Cloud

Calculate the weighted average cost of capital associated : Calculate the single break point associated with the firm's financial situation. Calculate the weighted average cost of capital associated with total new financing below the break point calculated in part. Calculate the weighted average cost of capit..
Write 8 sentences minimum on the film about hitler : Write one paragraph of 8 sentences minimum on the film about Hitler;- what is your assessment of Dr. Langer's work;
Are there any market trends that you will be capitalizing on : Are there any market trends that you will be capitalizing on? Discuss Online and Internet market trends and how you will leverage them? Has there been any growth in the market? Please provide specifics.
What does and does not constitute software security : Explain what process you would use test the software security. Justify your explanation. As part of your post, you may need to define what does and does not constitute software security.
Calculate the total remaining health of each army : Pass in and set each army (an army is an array list of Warriors). Calculate the total remaining health of each army. Print out the attack strength of each warrior of each army
The corporate charter of hawes corporation allows : The corporate charter of Hawes Corporation allows the issuance of a maximum of 100,000 shares of common stock. During its first two years of operations, Hawes sold
How do the financial statements for a corporation : How do the financial statements for a corporation differ from the statements for a proprietorship?
What is the value of abc stock : ABC Corporation pays a $10 per share annual dividend on its preferred stock. Given a 5% rate of return and assuming that this dividend policy will continue forever, what is the value of ABC stock
Rephrase the given articles : rephrase the given article:- there are a number of problems that the American health care unit facing at the moment.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write the definition of a method power

Write the definition of a method powerTo, which receives two parameters . The first is a double and the second is an int . The method returns adouble.

  Write a method called rectsum

Write a method called rectSum that will get the sum of a rectangle of elements within a 2D array of ints

  Write a program that presents an animated graphical model

Write a program that presents an animated graphical model of an elevator, that has at least four floors, with doors that open and close, and some indication that shows the car moving.

  Write the java code for classes team and player

Write the Java code for classes Team and Player. Declare the classes in package com.myleague.reg. Provide an implementation of all methods according to the given method names. You can use the class Random fromjava.util to randomly pick a student

  Using your musicalinstrument class

Finally, create a Java test class that simulates using your MusicalInstrument class.  In your test class you should at a minimum: a) Construct 4 instances of your instrument, b) tune your instruments, c) print the name of your instrument d) print ..

  Explain how operating systems and abstraction are related

Compare and contrast System Software and Application Software. Give an example of each. Abstraction is an important quality of an Operating System. Explain how Operating Systems and abstraction are related

  Develop a reliable transfer protocol over udp

Develop a reliable transfer protocol over UDP. Focus on a Stop- and-Wait protocol.

  Consider an algorithm for computing cubes using addition

You have a computer where multiplication is an enormously expensive operation compared to addition. Consider an algorithm for computing cubes using only addition (FYI: the first 5 cubes are 13 = 1, 23 = 8, 33 = 27, 43 = 64 and 53 = 125). This comp..

  Write a recursive program

Write a recursive program to compute the number of ways in which an integer k can be written as sum

  Write a java program that finds the temperature

Write a JAVA program that finds the temperature that is the same in both Celsius and Fahrenheit.

  A class is a blueprint for an object

A class is a blueprint for an object. A class may have a default constructor, a constructor with arguments, accessor methods, mutator methods, public fields, and private fields.

  System schedule on a multiprocessor-multicore environment

This program assignment is provided to let the students understand how to the Operating Systems schedule all the processes on a multiprocessor or multicore environment.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd