UW Home     CSE Home   Announcements    Message Board    Contact Info 

 
 
 

CSE143 Autumn 2004 Project #1 Part A

Jurassic Park! - A Virtual Dinosaur Safari 

Due: 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 toString() methods where appropriate, and so forth.

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.

Overview

To 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 Food

You 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 getCalories() method returns the number of calories (energy) absorbed when the Food item is eaten. Of course, you should add proper JavaDoc comments to this interface. You can add additional methods and constants to this interface if it makes sense for your program.

The Basic Dinosaur

You should create an abstract class Dinosaur that defines the common behavior and state shared by subclasses that extend Dinosaur.

Dinosaur Methods

A Dinosaur should provide at least the following behavior (i.e., include the following methods).

  • double getX() - return the longitudinal position of the dinosaur, in meters.
  • double getY()  - return the latitudinal position of the dinosaur, in meters.
  • void turn(double degrees) - turn the given number of degrees relative to the dinosaur's current direction. A negative value is a left turn, a positive value is a right turn.
  • void changeSpeed(double howMuch) - change the current speed of the dinosaur by the given amount in meters/second, either positive (speed up), or negative (slow down).  Note that a total negative speed would mean the dinosaur was going backwards.
  • void eat(Food lunch) - eat the given piece of food.
  • void move(double seconds) - update the position and other state of the dinosaur after moving for the given amount of time, which may be a fraction of a second, or may be considerably longer.  
  • String toString() - return a string representation of the dinosaur, which should include information useful for observing the dinosaur's state. At a minimum you'll want the current location, speed, and direction.

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:

  • newX = oldX + speed*sin(direction)*time
  • newY = oldY + speed*cos(direction)*time

(You can find functions to calculate sin and cos in class Math)

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 are particularly likely to override move to get different behaviors. There is a lot of room for creativity here. You could do some research and implement realistic move methods that model the energy and speed of different kinds of real dinosaurs (A Google search on "dinosaur speeds" turns up lots of interesting information about the mechanics of dinosaur locomotion. For example, some dinosaurs could reach a speed of 60 miles per hour), or you could create dinosaurs for an imaginary safari with unusual physics.

Dinosaur State

Your 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" Dinosaur

You should create at least three extended subclasses of Dinosaur to model different kinds of actual dinosaurs. These classes should have different behaviors in some way, probably by overriding method move among others. We suggest that at least one of these subclasses implement a very simple move method that moves by updating the dinosaur's position using the current speed and direction (the first option in the list above).

Unit Tests

A 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 In

When 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.