In this activity we make use of the methods defined in the class CarTracker.
In addition to the Solution document, the project for this activity contains the classes:
Your task is to locate a 'treasure' hidden somewhere on a grid system. The CarTracker class discussed in Unit 3 operates with a grid system, and so we can use CarTracker objects to help us determine where the treasure is by making use of information supplied about the location of the treasure.
You are given the following information.
Open the class TreasureHunt. Insert statements in the main method that will make the comparisons necessary to locate the site of the treasure, and work out the journey distance from Spyglass Hill to the Ship Inn via the treasure.
For example, we can construct a CarTracker object whose starting position is point A (11,5) and whose ending position is at SpyglassHill (8, 33) as follows:
CarTracker aToSpyglass = new CarTracker(11,5,8,33);
Then the expression aToSpyglass.greaterThan(5) tells if the distance from A to Spyglass Hill is more than 5km. This is one thing that must be true if A is where the treasure is. There are two other things that must be true.
We can perform the same tests for B's position.
See our TreasureHunt_Solution for one way to solve the problem.