Question: Lab Concepts: Using Arrays [ ] accessing elements in an Array [ ] looping through ( or processing ) an Array [ ] passing command
Lab Concepts:
Using Arrays
accessing elements in an Array
looping through or processing an Array
passing command line arguments to our Java programing
Level of our game changes we are making to our game:
Input mercenary names from command line
change our loop control variable from sentinel controlled loop to process all items in an array
Run our program from the command line
Level of our game changes we are making to our game:
Instead of taking input for each mercenary name, we pass in our troop list as a command line arguments
Update our loop from a sentinel controlled loop to a loop that processes each element in our String args array until there are no more troop names to process
pseudocode changes in blue
start mainStrings args
set militia
set totSalaries
loop start:
while names in args
get input for name base salary variable
Select
if mercenary name Kalinga can used name constant or literal constant, comment in your code which constant type you are using then shackle and imprison,
else continue to add mercenary to militia
set militia militia
set totSalaries totSalaries salary
maxpercent calcmaxpercentsalary
percent simulatenegpercentmaxpercent
negsalary calcnegsalarysalary percent
output your mercenary name and your contract values salary, negotiated salary and loot.
input number of months in battle
input Solidus loot value
input side a value of triangulated territory border to conquer
input side b value of triangulated territory border to conquer
input side c value of triangulated territory border to conquer
soliduspay calcpaynegsalary, months, percent, loot
calcdisplaysolidusdiffnegsalary, salary, months, percent, loot
angleA calcanglesidea sideb, sidec
angleb calcanglesideb sidea, sidec
anglec calcanglesidec sidea, sideb
Output formatted to decimal places side a side b side c and angle A angle B Angle C
end loop
Output battle cry, size of militia and total salaries committed by the empire for battle!
Output "UUKHAI!"
end main
method definitions
outside main but in class
double calcmaxpercents
s maxpercent
s maxpercent
s maxpercent
s maxpercent
s maxpercent
return maxpercent
double simulatenegpercentmaxpercent
return random number from range between maxpercent
double calcnegsalarysalary percent
return salary salary percent
double calcpaynegsalary, months, percent, loot
return negsalary x months loot x percent
void calcdisplaysolidusdiffnegsalary, salary, months, percent, loot
Calculate mercenary pay if was salary and loot
Calculate mercenary pay if salary and loot
Calculate difference between mercenary pay and salary
Calculate difference between mercenary pay and loot
Output formatted to decimal places mercenary actual pay in Solidus, what it would have been if salary, and the difference
Output formatted to decimal places mercenary actual pay in Solidus, what it would have been if loot, and the difference
double calcangleabc
Calculate angle territory border
return angle
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
