Overview · Learning Goals · Files Provided · How to Test · Specifications · toString Format · Constraints · Checklist · Submission · Grading

Overview

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.

Specification-driven project. Follow the written requirements exactly. Constructor behavior, delegation, invariants, and toString() formatting all matter.
Important model choice: This project uses a 1D distance model. We do not store (x, y) coordinates. Instead, we store only a non-negative distance from the center of the park.

Learning Goals

Files Provided

Classes to Implement

These files contain Javadoc and TODO: comments. You must complete the TODOs while keeping method signatures intact.

Provided Demo File (Read-Only)

Do not modify ElephantDemo.java. Your Elephant and Tracker implementations must work with the demo exactly as written.

Optional Grader Tester (For You)

Do not submit tester files. They are for your own development and debugging.

How to Test

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.

Compile and Run

javac *.java
java ElephantDemo

If provided, you may also run the tester for a score-based self-check:

javac *.java
java ProjectBTester
Exact output matters. Some tests (and future graders) depend on matching the required toString() format exactly.

Specifications

Class: Tracker

A Tracker stores and updates an elephant’s distance from the park center using the 1D distance model.

Note (invariant): The distance from the center must never be negative. If movement would make the distance negative, the distance should be set to 0.

Class: Elephant

An Elephant stores biological information and owns exactly one Tracker. The elephant delegates movement and park-boundary checks to its tracker.

Note (delegation): The Elephant class does not compute distances. It delegates movement and inside/outside checks to the associated Tracker.

Strict toString() Format

Important: These formats are strict. Match them exactly (labels, punctuation, spacing).

Tracker.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]
Delegation rule: Elephant.toString() must obtain the tracker text by calling tracker.toString(). Do not manually rebuild the tracker string.

Implementation Constraints

Testing Checklist

Submission

Submit only: Do not submit:

Grading (18 points total)

The project is graded for correctness and adherence to the written specification. A high-level breakdown: