• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Army Regiment Program  RSS feed

 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

I have some code written for class that is due soon and I can't seem to figure out why it is that my Update method isn't working properly. Here are the specifications for the assignment:

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
• update the list (i.e., 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 then call the methods that update the list and print the report.

4. Output will be a series of reports --- one report for each of the 20 weeks.

5. Each weekly report should begin with an appropriate heading, including the week number.


6. 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 of the regiment.
 Remember that once a regiment has gone to the front, it will not appear in any of the subsequent reports.

 To prevent the weekly reports from "scrolling" by too fast to be read, execute this statement after each report is printed:

JOptionPane.showMessageDialog(null,"Next Report?") ;



Here is the code I have so far for the ArmyRegiment class:

import java.util.ArrayList;

class Regiment {

private String name; //Regiment name
private int regNumber; // Regiment's number
private int regStrength = 1050; // Number of soldiers in regiment.


and here is the test class:


here's the contents of the txt file that is used as input:
1 Aardvarks
2 Begonias
3 Chrysanthemums
4 Dhalias
5 Elephants
6 Ferrets
7 GilaMonsters
8 Hyraxes
9 Ibex
10 Jackyls
11 KimodoDragons
12 Lemurs
13 Marigolds
14 Nonames
15 Opossums
16 Porcupines
17 Quahogs
18 Rhododendrons
19 Swordfish
20 Tapirs



The while loop in my test class is wrong and it continues even when the arraylist is empty. I just can't figure out why my Update method isn't working. I want it to use the initial values that I originally print then add 100 to all except the 5th regiment "Elephants" who only get added 30. Any help would be appreciated.
 
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joel,
Welcome to Javaranch!
In future please UseCodeTags to wrap around your source code. This time I have done it for you and see how pleasant the code looks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!