Course ProjectThis homework is the first part of the course project, which is to implement a modified version of the Oregon Trail computer game. If you are not familiar with the game, then you should read the article at that link. There are a number of classes that will be required for this project, split among the next few homeworks and labs.
Don't worry if you don't understand all of what these classes do (or why they are all needed!) at this point -- it will become more clear over the next few assignments. PurposeFor this homework, you are responsible for implementing the Location and Person classes. You must submit these two files, along with the Game.java file. We are not providing skeleton code for Location.java and Person.java. A note about the due dateWe got this homework out a bit later than expected. In an effort to compensate, we made this assignment a bit easier. Other than the constructors and accessors/mutators, there are only 5 methods that you need to implement (three in Location, two in Person). Also, we have provided a lot of test code in Game.java that tests the Person class (you only have to provide, in Game.java, the test code for the Location class). If you still think this is totally unfair, and need to vent your wrath at somebody, please come speak to one of the two instructors in person (wrath is much more interesting when vented in person, rather than by e-mail). Getting StartedMost of the classes in this project are dependent on other classes. For that reason, you will need to download skeleton code for a few of the other classes to complete this homework:
Note that the ONLY thing in this homework that should be static is your main() method in the Game class. If anything else is static, you are doing something wrong. Game classWe provide a Game.java file, which includes a number of things that you will need for the homework. Random ValuesTo choose a random value, you will need to use the Random class. We have provided a object of class Random for you to use. YOU MUST USE THIS ONE, as we will need that for testing and grading. In order to create a random integer, you would call Game.random.nextInt(x), where x is any integer value. This will return a random number between 0 and x-1. So if you call Game.random.nextInt(15), it will return a random number between 0 and 14. You can choose a random boolean via Game.random.nextBoolean(), etc. Game constantsThe Game class also defines a number of constants that will be used in this project; only a few will be needed for this homework. main() methodYou will have to modify the main() method, as described below. You should read the homework through before you begin, as completing the main() method will be easier if done while developing your Location and Person classes. Descriptions classThis class is responsible for generating the names and types of terrain in the game, which are used in the Location's default constructor, below. You will be implementing the Descriptions class in lab 10. In the meantime, the one we provide has two methods that are needed for this assignment:
Because the methods are static, you need to call them by the class name, not the object name. Thus, to find an adjective for a particular terrain, you call Descriptions.generateRandomTerrainAdjective(). This returns a String. To find the description of the terrain type, you call Descriptions.getTerrainTypeName(), passing in the type number of the terrain whose name is needed. This method also returns a String. Once you finish your Descriptions.java file in lab 9, you can use that instead of the Descriptions.class file that we provide. Location classThe first class you must implement represents a single spot on the game board. As with the Person class, nothing should be static, all fields must be private, and (unless specified otherwise), all methods public. Your Location class needs to be declared public, and in a Location.java file. Nothing should be static. All fields must be private. Unless specified otherwise, all methods must be public. PropertiesThe Location class only has a number of properties:
ConstructorsThere are three constructors for this class. Your constructors should call the mutators instead of setting the fields directly! You may explicitly initialize the instance variables when they are declared, of course.
Please make sure you understand what each of these constructors does -- if you don't, then you will have trouble with the rest of the assignment. Accessors and MutatorsYour class needs to have an accessor and mutator for EACH of the properties listed above. The methods must following the standard naming scheme (i.e. getDepot(), setTerrainType(), etc.). As discussed in lecture, your mutators should also check for "bad" values. You have a number of options to do when you find a bad value:
Exiting the program would normally be allowed, but it will cause our testing of your program to not work as well, so please don't exit the program when a bad value is found. Other MethodsThere are three other methods that are required for this class. Note that the chooseTerrainType() method is private.
Person ClassThe second class you must implement is the Person class. Objects of this class will be created to represent each of the people in your party. Your Person class needs to be declared public, and in a Person.java file. Nothing should be static. All fields must be private. Unless specified otherwise, all methods must be public. PropertiesIt should have the following properties.
Please make sure you understand what each of those properties does -- if you don't, then you will have trouble with the rest of the assignment. ConstructorsYour Person class should only have one specific constructor (and no default constructor). Your constructors should call the mutators instead of setting the fields directly! You may explicitly initialize the instance variables when they are declared, of course.
Accessors and MutatorsYour class needs to have an accessor and mutator for EACH of the properties listed above. The methods must following the standard naming scheme (i.e. setHealth(), getName(), etc.). Your mutators should check to make sure that the variables are not set to invalid values! For example, you can't set the health to greater than the maximum health value, etc. Other MethodsThere are two additional methods that are needed for the Person class.
Your main() method in the Game.java file should test all of the methods that you implement. You will notice that it currently tests all of the Person methods. The basic idea is to call a method, and verify that it does what it was supposed to do by calling an accessor method. For example, by calling the Location's specific constructor, it is supposed to set a number of values. You need to verify this by calling the accessor method, and checking to see that they return the right values. You can use specific values for these tests -- i.e., you can create a Location whose appearance is set to a String 'foo', and then check to see that the appearance of the Location's appearance is indeed 'foo'. Where to StartWork on the methods one by one, making sure that each one works before moving onto the next one. While the main() method may seem like a lot of work, there are a couple of things that will make it much easier. If you add the code to Game.java as you go along, it will make it much easier. The idea is to implement a method or two, and then add the test code to Game.java. Then make sure it compiles and works properly. Then go onto adding more methods. If you get stuck in a method (i.e. can't get it to work, it won't compile, etc.), then move onto another one, and come back to the one that is giving you problems. Also note that the code for the testing of the accessors and mutators is going to be very similar -- you can just copy-and-paste the code, then modify it to use the other accessors/mutators. Lastly, this homework will be much easier if you work through it one method at a time. Write the first method, and then sufficiently test it in your main() method. Then write the second method, and sufficiently test it in your main() method. This will make the entire homework much easier, and it will take much less time to complete. Good Programming PracticesAll the good programming practices from HW 1 should be included here as well. Since you are providing code in the main() method of the Game class to test your other code, you don't need to include execution runs as comments. SubmissionWhen you are finished, submit the Location.java, Person.java, and Game.java files. |