







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








Computer Programming I Instructor: Greg Shaw COP 2210
(ArrayLists)
The following story is told about the Russian army at the time of the Russo-Japanese War: It seems that 20 regiments were in a continuous process of formation. The first had 1000 men, the second had 950, the third 900, and so on down to the twentieth regiment, which garrisoned only 50. During each week, 100 men were added to each regiment, and at week's end, the largest regiment was sent off to the front. Apparently, the commander of the 5th regiment was a wonderful chess player. To delay his eventual trip to the front, the General of the Army (who happened to be his chess partner) sent him only thirty new recruits each week (instead of 100). Write a Java program that tells which regiment is sent to the front each week, shows the status of the remaining regiments, and determines exactly how long it takes for the chess-playing commander to go to the front.
19 Swordfish 20 Tapirs Regiment.java /* File: Regiment.java
// If it's the fifth regiment, add 30 - not of 100 if ( regiment.getName().equals("Elephants") ) { // Add 30 soldiers, not 100 soldiers regiment.plusStrength(Regiment.R5) ; } else // Otherwise { // Add 100 soldiers to the regiment regiment.plusStrength(Regiment.R0) ; } } } /**
String name = regiment.getName() ; // Get regiment's name int strength = regiment.getStrength() ; // Get regiment's strength // Heap up all the data to initialized string, report report += Align.center(number, 14) + Align.center(name, 16)
list (Only Once!) regiments.remove(first) ; } // If Max belongs to the very first strength if (Max == initialMax) { // Then show the following message about the first regiment fronts = "Regiment " + first.getName() + " will be on"
ArmyOut.java /* File: ArmyOut.java
String frontLine = list.maxStrength() ; System.out.println(frontLine) ; } } }