|
|
CSE143 Autumn 2004 Project #1 Part AJurassic Park! - A Virtual Dinosaur SafariDue: Wednesday, October 13, at 9:00 pm. No late assignments will be accepted.This is the first part of a 3-part project to create a virtual dinosaur safari. For the first part, you are to implement a collection of Dinosaur classes and main programs to test them out. Later parts of the project will add an event-driven graphical user interface. The project is open-ended with opportunities to earn extra credit (which will be awarded when the whole assignment is finished). A few possibilities are mentioned below and others will be discussed in later parts of the project. You should work with your assigned partner on this project using the pair programming style discussed in class. While you may want to think about the project, sketch ideas, and try them out on the computer yourself (when your partner is not around), it works best if the two of you write the actual project together at a single computer, trading off the keyboard at least every 5 or 20 minutes. You and your partner will turn in a single set of files. After the final part of the project is done, each of you will individually individually write a final report. (Details about that will be supplied later.) Grading: When the project is complete (all 3 parts), your project
will be evaluated both for how well the code works and how well it is written
and tested. For the intermediate parts of the project, we will try to give
you quick feedback on the scale of 0-3: 3=no major problems, 2=something
needs to be fixed, 1=serious trouble, and 0=no credible effort. Be sure
to include appropriate JavaDoc and other comments in your code, use meaningful
names, indent sensibly, provide Keep track of the major design decisions, algorithms, and tests you perform to verify your code is working. You will be asked to include a summary of these in the report that you will write individually at the end of the final part of this project. OverviewTo create a virtual dinosaur safari, we need to model the dinosaurs that live in it. A virtual dinosaur has various properties such as its location, current direction, current speed, and so on. Location will be an (x, y) coordinate on a plane – think of the environment as a field which we're looking down on from above. A dinosaur can be asked to move for a certain length of time, changing its position and possibly other properties (more on this below), and can be asked to turn, speed up, or slow down. A dinosaur can also eat food, either other dinosaurs, or plants (if you choose to create a Plant class). Dinosaurs will be either carnivores (only eating other dinosaurs) or herbivores (only eating plants). You must create at least three distinct kinds of dinosaurs with different behaviors, using inheritance to factor common properties of different kinds of dinosaur into a superclass. You are welcome to have more than three kinds of dinosaur or more elaborate inheritance hierarchies to model various kinds of animals and plants and elements of the environment, but this is not required. You should use real-world units of measurement for the various quantities. Positions should be measured in meters from a base location (such as the bottom-left corner or center of the field). Speed should be measured in meters per second and directions in degrees clockwise from the vertical y axis. Food energy should be measured in calories. Interface FoodYou should include the following Java interface in your program. All edible things in the virtual dinosaur safari will implement this interface. public interface Food {
double getCalories();
}
The The Basic DinosaurYou should create an abstract class Dinosaur MethodsA
You should also include suitable constructors to initialize the state of a new dinosaur to sensible values. You are free to add additional methods, and in later parts of the project will probably want to do so. But this minimal collection will be enough to get started. The move method is a key to the dinosaur safari simulation, and is one way to have different behavior for different kinds of dinosaur. Think of ways in which to make your dinosaurs act differently. They could move using a simple position update. A simple-minded dinosaur would just move to a new position using its current speed and direction. If the dinosaur is located at position (oldX, oldY), its new position, (newX, newY) can be calculated as follows:
(You can find functions to calculate sin and cos in class You could also make the dinosaur move randomly, where it would first make some small random changes in its direction or speed or both, then update its position. You have a lot of room to be creative! Each dinosaur should have a rate at which it consumes energy while moving. The dinosaur should keep track of the energy (calories) it has eaten and it should speed up or slow down depending on how much energy it has and how much it weighs. Its energy should also decrease as it moves depending on its speed and energy consumption rate. Different subclasses of Dinosaur StateYour dinosaur should include appropriate instance variables to implement the behaviors specified above as well as any that you add. These will include the current (x,y) location of the dinosaur, direction, speed, weight, energy level and energy consumption rate (in calories per hour, depending on whether the dinosaur is standing still or moving). The exact details are up to you. Remember to set visibility (public, private, protected) appropriately. "Concrete" DinosaurYou should create at least three extended subclasses
of Unit TestsA key part of this assignment is to test your dinosaur objects carefully to be sure that they move as expected. That means creating instances of your dinosaur classes, calling their methods, and verifying that instance variables and other observable state changes as you predict. In particular, be sure that you and your partner understand the equations and how the state of the dinosaur should change as it moves, then verify that they actually do work that way. Be sure to test all the major behaviors of your dinosaurs so that in the next part of the project we can assume that they behave properly and can move on to other issues. You should implement a set of JUnit tests to automatically test your dinosaurs. It is very helpful if you think about your testing strategy as you design and implement your classes. It is much harder to try to come up with tests after the fact than it is to develop them as you think through the code. In fact, if you think about and understand the tests first, it will make the job of coding the actual dinosaur objects easier. What to Turn InWhen you are done, use this online turnin form to turn in the source files for your program and for the unit tests that verify that they work as expected. You can turn in the project more than once - we'll grade the last version you turn in. In particular, if you want to go beyond the basic requirements, we strongly suggest that you turn in a project that meets the basic requirements first, then add the extras and turn in what you can before the deadline.
|