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)Elephant.javaTracker.java
These files contain Javadoc and TODO: comments. You must complete the TODOs while
keeping method signatures intact.
ElephantDemo.javaElephantDemo.java.
Your Elephant and Tracker implementations must work with the demo exactly as written.
ProjectBTester.java (for development / self-checking)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
If provided, you may also run the tester for a score-based self-check:
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.javaThe project is graded for correctness and adherence to the written specification. A high-level breakdown:
Elephant and TrackertoString() formatting