Modifications and advice for Project 5 are listed here in reverse chronological order, with new additions at the top.
Sure. It's easier to program, and that's how Unix does it.
You may provide additional error messages that provide more-detailed feedback, but please follow the example of those that are specified. Please keep them very brief and to the point.
Q: There was a call to getInstance() when calling stringListToModel() in the P4.java "try" block, but it is no longer there in the P5.java "try" block. Why not? P4.java had
(MaritimeModel.getInstance()).stringListToModel(stringList);
but P5.java has
MaritimeModel.stringListToModel(stringList);
A: Since stringListToModel() and modelToStringList() should have been defined as static (they were specified as "class methods" in Project 4), either of these lines of code would do the same thing because of an ugly little detail in Java that you can call a static method with either the name of the class OR an instance of the class. So, if stringListToModel() really is static, the extra characters in the second line above are not only unnecessary and do nothing, but they also potentially confuse the programmer into thinking that stringListToModel() is an instance method when it is really a class method.
We will continue to maintain and update a list of suggested setters, getters, and other methods that you might want to use in your project, but you no longer need to adhere to this list. Originally, we were asking you to use this list for strong "cohesion" between your code and ours, and so that we could swap out one of our modules with one of yours when grading. We are no longer limiting you to the method names, signatures, and functionalities listed here, and we will not swap our modules with yours when grading your projects.
However, when designing your own methods, you must do the following:
class MaritimeModel
class SimObject
class MaritimeModel
class View
The sail command will be simplified in the "Command Set". The modification is that the second two sail commands have been given unique command names.
- sail <ship-name> <island-name> <speed>
- Tell a ship to set sail to an island at a given speed.
- sailcr <cruise-ship-name> <island-name-1> [island-name-2 ...] <speed>
- Tell a cruise ship to set sail for any number of islands, in the order they are listed.
- sailoc <pirate-ship-name> <X> <Y> <speed>
- Tell a pirate ship to set sail to destination (X,Y).
The following line, for example,
Island Hawaii (6.00, 1.00) has 200 tons of fuel.
should be
Island Hawaii (6.00, 1.00) has 200.00 tons of fuel.
Change the units of the fuel consumption rate from "tons of fuel burned per nautical mile" to "nautical miles travelled per ton of fuel". This is an important change. It flips the measure.
Sure. Good question. Here you go.
Ship QE2 Cruise_Ship 12 10 12 0.1 Ship <Name> <ShipType> <Loc X> <Loc Y> <Max Speed> <Fuel Consumption Rate> Island Cove 98.999 10.733 5.0002 0.1 Island <Name> <Loc X> <Loc Y> <Fuel Level> <Fuel Production Rate>
A: Start by carefully reading the project specification (and this addendum) from beginning to end. It will help you to understand the scope of the project. Take notes as you go on interesting or unclear details. Sketch out the project and the interaction among the different modules as you go. When you are done, email 211staff@cs.uoregon.edu with any questions.
Then, decide which Project 4 code to start with. If you didn't get full credit, decide how quickly and easily you can fix your code, or whether you should use the solution provided.
After this, there are a number of ways to proceed. Here is how I am doing it:
The try block in P5.java should include all of the following:
try
{
// Read the file into the stringList.
fileName = FileUtils.fileToStringList (fileName, stringList);
// Load the stringList into the model.
MaritimeModel.stringListToModel(stringList);
// Create a pointer the model
MaritimeModel model = MaritimeModel.getInstance();
// Create and initialize the view.
View view = new View();
model.addView(view);
model.plotAll();
// Create the controller.
Controller controller = new Controller (model, view);
// Run the simulation.
controller.run();
// After the simulation, make sure the stringList is cleared.
stringList.clear();
// Save the model to the stringList.
MaritimeModel.modelToStringList(stringList);
// Save the stringList into the file.
FileUtils.stringListToFile(stringList, fileName);
}
Three things:
Here is a sample new input file: world.txt
Here is the output file that should be created from this input file after no ship movements: world-new.txt
Here is an input file with one error in each line: world-errors.txt. The errors for each line are as follows:
All doubles should be rounded to two decimal points in the data file and in the screen printouts. A technique for accomplishing this is discussed in the Sun Java Tutorial. Do a google search on "java tutorial decimal format".
Three corrections:
<pirate-ship-name> has caught <ship-name>.