Overview · Learning Goals · Files Provided · How to Test · Specifications · toString Format · Constraints · Checklist · Submission · Grading
In this project you will implement two Java classes that model objects and their relationship: Elephant and Tracker. Together, these classes represent a simplified park-tracking system where each elephant has a tracker that stores its distance from the center of a park.
toString() formatting all matter.
this(...)Elephant has a Tracker)toString() with a strict formatElephant → Tracker)Download all four files and place them in the same directory.
Elephant.javaTracker.java
These files contain Javadoc and TODO: comments. Complete the
TODOs while keeping the required method signatures intact.
ElephantDemo.java
The demo creates a population of elephants, repeatedly moves them, and
displays the results. Use it to see your Elephant and
Tracker classes working together in a small application.
ElephantDemo.java.
Your Elephant and Tracker implementations must
work with the demo exactly as written.
ProjectBTester.java
(basic checks for development and debugging)
The tester checks several specific parts of your implementation and can help you identify common problems while you work.
ElephantDemo.java or
ProjectBTester.java.
Submit only the files identified in the Submission section below.
This project includes a provided demo program that repeatedly moves a herd of elephants and prints their state. If your classes are correct, the demo will compile and run without errors.
javac *.java
java ElephantDemo
You may also run the basic tester to check specific parts of your implementation:
javac *.java
java ProjectBTester
toString() format exactly.
Tracker
A Tracker stores and updates an elephant’s distance from the park center
using the 1D distance model.
Tracker() places the elephant at the center and uses a default radius of 30 kmTracker(double distanceFromCenter, double parkRadius)move(double x) randomly moves toward or away from the center by x kmisInsidePark() returns whether distanceFromCenter <= parkRadiustoString() must follow the strict format belowElephant
An Elephant stores biological information and owns exactly one Tracker.
The elephant delegates movement and park-boundary checks to its tracker.
Elephant class does not compute distances.
It delegates movement and inside/outside checks to the associated Tracker.
TrackerElephant() assigns a random age in [1, 60], a random sex, and creates a default TrackerElephant(int age, char sex, Tracker tracker)this(...)move(double delta) delegates to the trackerisInsidePark() delegates to the trackertoString() must follow the strict format belowtoString() FormatTracker.toString()Must return exactly this style:
Tracker[distance=DIST km, radius=30.0 km, inside=BOOLEAN]
Note: DIST will vary (it is a number). BOOLEAN is either true or false.
Elephant.toString()Must return exactly this style:
Elephant[age=AGE, sex=SEX, TRACKER_STRING]
Elephant.toString() must obtain the tracker text by
calling tracker.toString(). Do not manually rebuild the tracker string.
main methods to Elephant or TrackerElephant or Trackerstatic instance variablesthis(...) to avoid duplicate initialization codejavac *.java compiles without errorsElephantDemo runs without crashingthis(...) (no duplicate initialization)Elephant.move(...) delegates to Tracker.move(...)Elephant.isInsidePark() delegates to Tracker.isInsidePark()toString() output matches the strict formats exactlyElephant.javaTracker.javaElephantDemo.javaProjects will be evaluated for both correctness and adherence to the project specifications.
Your project will be evaluated on:
toString() formatting