Programming
Assignment #9
(The ArrayList
Class)
I.
Problem Statement
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.
II.
Specifications
1.
Create a class to
represent a regiment. Each regiment
knows its regiment number, name, and strength (number of men).
2.
Create another
class to represent an army (an army is a collection of regiments). Your army class will feature separate methods
to do each of the following:
·
add a regiment to
the list
·
add new men to
each regiment
·
find the largest
regiment
·
print a report
3.
Your test class
will read the regiment number and name for each regiment from a data file,
until eof, compute the number of initial recruits for the regiment, create a
Regiment object, and add it to the list.
Then, for each week of the simulation, it will call the methods that add
men and print the report.
4.
Output will be a
series of reports --- one report for each of the 20 weeks.
5.
Output should be
written to a file.
6.
Each weekly
report should begin with an appropriate heading, including the week number.
7.
The report should
state which regiment is being shipped out that week, and data on the remaining regiments
(i.e., those which have not yet gone to the front) should be in column form, neatly
aligned, with headings. For each
remaining regiment print the regiment number, name, and the current strength
8.
Once a
regiment has gone to the front, it should not appear in any of the subsequent
reports.
F
To earn
credit, your Army class must use a generic ArrayList-of-Regiment – not an array
- as its only data structure
III. Date dueDate = new Date(12,3,2019) ;
(Tuesday,
December 3rd)
F
Assignments
will be accepted without late penalty until 12:30 on Thursday, 12/5
F
Assignments
will not be accepted after 12:30 on Thursday, 12/5
IV.
High-Level Algorithm for the Assignment
·
Create the
regiments and add then to the army
·
For each week of
the simulation, do:
Ø
Add men to each
remaining regiment
Ø
Find the largest
regiment
Ø
Print the weekly
report
Get Free Quote!
312 Experts Online