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

Download all four files and place them in the same directory.

Download Elephant.java Download Tracker.java Download ElephantDemo.java Download ProjectBTester.java

Classes to Implement

These files contain Javadoc and TODO: comments. Complete the TODOs while keeping the required method signatures intact.

Provided Demo File

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.

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

Basic Project Tester (Self-Check)

The tester checks several specific parts of your implementation and can help you identify common problems while you work.

This tester performs only basic checks. Passing all of these tests does not guarantee that your project is completely correct.
Do not submit ElephantDemo.java or ProjectBTester.java. Submit only the files identified in the Submission section below.

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

You may also run the basic tester to check specific parts of your implementation:

javac *.java
java ProjectBTester
Exact output matters. Some tests 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

Projects will be evaluated for both correctness and adherence to the project specifications.

Your project will be evaluated on:

Remember: The provided tester performs only basic checks. Passing all of its tests does not guarantee full credit on the project.