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 7 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 7 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 main(Strings args[])
set militia =0
set totSalaries =0
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 +1
set totSalaries = totSalaries +salary
max_percent = calc_max_percent(salary)
percent = simulate_neg_percent(max_percent)
neg_salary = calc_neg_salary(salary, 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
solidus_pay = calc_pay(neg_salary, months, percent, loot)
calc_display_solidus_diff(neg_salary, salary, months, percent, loot)
angle_A = calc_angle(sidea, sideb, sidec)
angle_b = calc_angle(sideb, sidea, sidec)
angle_c = calc_angle(sidec, sidea, sideb)
Output formatted to 2 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 calc_max_percent(s)
s 0-500 max_percent =20
s 501-1000 max_percent =25
s 1001-2000 max_percent =50
s 2001-3000 max_percent =75
s 3000 max_percent =100
return max_percent
double simulate_neg_percent(max_percent)
return random number from range between 0- max_percent
double calc_neg_salary(salary, percent)
return salary - salary * percent
double calc_pay(neg_salary, months, percent, loot)
return neg_salary x months + loot x percent
void calc_display_solidus_diff(neg_salary, salary, months, percent, loot)
Calculate mercenary pay if was 100% salary and 0% loot
Calculate mercenary pay if 0 salary and 100% loot
Calculate difference between mercenary pay and 100% salary
Calculate difference between mercenary pay and 100% loot
Output formatted to 3 decimal places mercenary actual pay in Solidus, what it would have been if 100% salary, and the difference
Output formatted to 3 decimal places mercenary actual pay in Solidus, what it would have been if 100% loot, and the difference
double calc_angle(a,b,c)
Calculate angle territory border
return angle

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!