Lab 9: The last project - part 2
Released: 11:59 PM Sunday, July 26th, 2020.
Due:
The last stretch
The last project can be found in the website. If you haven’t, please read the project description!.
The final step of the project is to add the ability to configure the simulation based on the contents of a configuration file. And report the results of the simulation in another.
The path for both the input and output files will be given as a program argument (check the first “Friend database” class). E.g.:
java Project3 configuration.txt output.txt
Input for the program
The format of the input file will be very straight-forward. Like in the example below:
3
7
Azaghâl
Balin
Dís
Durin
Gimli
Náin
Thrór
3
3 2
3 1
4 3
- The first line represents the number of dwarfs that must be in a team.
- The second line represents the number of dwarfs working under the manager (7). Use it to load their names.
- The following 7 lines contain the names of the dwarves.
- The 10th line contains the number of pots of gold coins (3).
- The following 3 lines contain the number of coins in each of the pots and the number of days that takes to travel to that pot of gold.
| 1. Modify your program to load the values from such a file. |
Output from the program
The next part of this week’s assignment is to write the log of each day of work into a logfile. The following example is based on the configuration I gave to you hard-coded in the file.
0,false,false,false,Azaghâl,Balin,Dís,Durin,Gimli,Náin,,,,0
1,false,true,false,,,,,,,,,,3
2,true,false,false,,,,,,,,,,6
3,false,false,false,,,,,,,Durin,Gimli,Náin,6
4,false,false,false,,,,,,,,,,6
5,false,false,false,,,,,,,,,,6
6,false,false,true,,,,,,,Azaghâl,Balin,Dís,9
7,false,false,false,,,,,,,,,,9
8,false,false,false,,,,,,,,,,9
9,false,false,true,,,,,,,,,,10
The format above is called CSV (comma separated values). Because, ya know, they are values. And the are separated. Ya know, by commas :) You can even try to open the file using excel (or similar program)
Decoding row “0”:
- On day 0
- No team returned from pot 0
- No team returned from pot 1
- No team returned from pot 2
- Azaghâl, Balin, and Dís were assigned to pot 0
- Durin, Gimli, and Náin were assigned to pot 1
- No one was assigned to pot 2
- We have zero coins in our vault
Decoding row “6”:
- On day 6
- No team returned from pot 0
- No team returned from pot 1
- A team returned from pot 2
- No one was assigned to pot 0
- No one was assigned to pot 1
- Azaghâl, Balin, and Dís were assigned to pot 2
- We have 9 coins in our vault
| 2. Have the dwarf manager write a daily report using the format above. |
Note: there are no spaces in the output
Note 2: The number of values in 1 line will vary depending on the number of elements in a single team, and on the number of pots.
Other examples
Example 1
config:
3
10
Azaghâl
Balin
Dís
Durin
Gimli
Náin
Thrór
Bofur
Kili
Fili
7
3 2
3 1
4 3
3 5
5 3
9 2
1 1
Output:
0,false,false,false,false,false,false,false,Azaghâl,Balin,Dís,Durin,Gimli,Náin,Thrór,Bofur,Kili,,,,,,,,,,,,,0
1,false,true,false,false,false,false,false,,,,,,,,,,,,,,,,,,,,,,3
2,true,false,false,false,false,false,false,,,,,,,,,,,,,,,,,,,,,,6
3,false,false,true,false,false,false,false,,,,,,,Durin,Gimli,Náin,,,,,,,,,,,,,9
4,false,false,false,false,false,false,false,,,,,,,,,,Azaghâl,Balin,Dís,,,,,,,,,,9
5,false,false,false,false,false,false,false,,,,,,,,,,,,,Thrór,Bofur,Kili,,,,,,,9
6,false,false,true,false,false,false,false,,,,,,,,,,,,,,,,,,,,,,10
7,false,false,false,false,false,false,false,,,,,,,,,,,,,,,,,,,,,,10
8,false,false,false,false,true,false,false,,,,,,,,,,,,,Durin,Gimli,Náin,,,,,,,13
9,false,false,false,true,false,false,false,,,,,,,,,,,,,,,,,,,,,,16
10,false,false,false,false,false,false,false,,,,,,,,,,,,,,,,Thrór,Bofur,Kili,,,,16
11,false,false,false,false,true,false,false,,,,,,,,,,,,,,,,,,,Azaghâl,Balin,Dís,18
12,false,false,false,false,false,true,true,,,,,,,,,,,,,,,,,,,,,,22
13,false,false,false,false,false,false,false,,,,,,,,,,,,,,,,Durin,Gimli,Náin,,,,22
14,false,false,false,false,false,false,false,,,,,,,,,,,,,,,,,,,,,,22
15,false,false,false,false,false,true,false,,,,,,,,,,,,,,,,Azaghâl,Balin,Dís,,,,25
16,false,false,false,false,false,false,false,,,,,,,,,,,,,,,,,,,,,,25
17,false,false,false,false,false,true,false,,,,,,,,,,,,,,,,,,,,,,28
Example 2
config:
2
3
Bofur
Kili
Fili
1
9 2
Output:
0,false,Bofur,Kili,0
1,false,,,0
2,true,,,2
3,false,,,2
4,false,Bofur,Kili,2
5,false,,,2
6,true,,,4
7,false,,,4
8,false,Bofur,Kili,4
9,false,,,4
10,true,,,6
11,false,,,6
12,false,Bofur,Kili,6
13,false,,,6
14,true,,,8
15,false,,,8
16,false,Bofur,Kili,8
17,false,,,8
18,true,,,9
Example 3
config:
1
3
Bofur
Kili
Fili
4
3 5
5 3
9 2
1 1
Output:
0,false,false,false,false,Bofur,Kili,Fili,,0
1,false,false,false,false,,,,,0
2,false,false,true,false,,,,,1
3,false,true,false,false,,,,,2
4,false,false,false,false,,Fili,,,2
5,true,false,false,false,Kili,,,,3
6,false,false,false,false,,,,,3
7,false,true,false,false,,Bofur,,,4
8,false,false,false,false,,,,,4
9,false,false,false,false,,,Fili,,4
10,true,true,false,false,,,,,6
11,false,false,true,false,,,,,7
12,false,false,false,false,Bofur,Kili,,,7
13,false,false,false,false,,,Fili,,7
14,false,false,false,false,,,,,7
15,false,true,true,false,,,,,9
16,false,false,false,false,,,,,9
17,true,false,false,false,,Kili,Fili,,10
18,false,false,false,false,,,,,10
19,false,false,true,false,,,Bofur,,11
20,false,true,false,false,,,,,12
21,false,false,true,false,,,Fili,,13
22,false,false,false,false,,,,Kili,13
23,false,false,true,true,,,Bofur,,15
24,false,false,false,false,,,,,15
25,false,false,true,false,,,Kili,,16
26,false,false,false,false,,,,,16
27,false,false,true,false,,,Bofur,,17
28,false,false,false,false,,,,,17
29,false,false,true,false,,,,,18
Extra credit
You want more, you say? Well, what about this for extra 10%?
- Make sure every dwarf does some work!
You may notice that in the original example Thrór never gets a change to go on an adventure. Well, you can fix that!
Make sure all dwarves have an opportunity to go in an adventure! You may assume that there are enough trips to use all dwarves.
How? Well maybe you can keep track of which dwarves were already assigned. Or maybe your program can remember where the last assignment ended?
Good luck! And if there is something else you want to try for extra credit, let me know and I’ll let you know if that’s acceptable.