# COSC 1010 Introduction to Software Problem Solving

## Homework Assignment #4

"And he made a molten sea, ten cubits from the one brim to the other: round all about, and his height five cubits: and a line of thirty cubits did compass it round about. And under the brim of it round about there were knops compassing it, ten in a cubit, compassing the sea round about: the knops cast in two rows, when it was cast."
-- 1 Kings 7:23-24
Due: Wednesday, September 29th, 11:00am CDT
Submit: Turn in your "Project4.java" using the D2L dropbox.
Work may be completed in teams. The names of both partners must appear in a comment block at the top of your file for credit to be given.

### The Treasure Hunt

The classic pirate's treasure map consists of an opaque list of orienteering steps. Starting from a known origin, a treasure hunter follows a series of directions given as distances (in paces) and direction turns (often in compass bearings.) For this assignment, your team will write a program that computes the end coordinates of such a treasure hunt.

Computers are good with numbers, so to make it a little more challenging, each step of the treasure hunt will consist of three numbers:

• Distance: an integer number of paces.
• Bearing: an integer number of degrees to turn before pacing. Degrees will be interpreted as compass bearings, so 0 degrees means do not turn; 90 degrees means turn to your right; -90 degrees (or 270 degrees) means turn left, etc. Positive and negative integers between -360 and 360 (inclusive) should be allowed.
• Declination: an integer number of degrees indicating angle from horizontal. A declination of 45 degrees would be up a steep hill; -5 degrees would be a gentle downslope; 0 degrees is horizontal. Positive and negative integers from -90 to 90 (inclusive) should be allowed.
• At each step, print out the X, Y, and Z coordinates and the bearing the treasure hunter is facing.

When there is no more input, print the final end point, and the closest and farthest points along the journey.

### Example Runs

In the examples below, I use text in blue to distinguish the output of the program from the input I typed. This is for purpose of clarity only; your program will not print text in different colors.

Example #1

Project 4 - Orienteering
Please enter a list of triples (distance, bearing, declination):
10 45 0
Bearing 45 at (7,7,0)
10 45 0
Bearing 90 at (17,7,0)
Final position : (17,7,0)
Closest point to origin : (7,7,0)
Farthest point from origin: (17,7,0)

Example #2

Project 4 - Orienteering
Please enter a list of triples (distance, bearing, declination):
50 0 36
Bearing 0 at (0,40,29)
50 90 -36
Bearing 90 at (40,40,0)
50 90 36
Bearing 180 at (40,0,29)
50 90 -36
Bearing 270 at (0,0,0)
Final position : (0,0,0)
Closest point to origin : (0,0,0)
Farthest point from origin: (40,40,0)

### Notes

• Note that the treasure map is completed when the end-of-file marker is reached (Ctrl-Z if you're typing input manually).
• Redirect test input into your program in Morbius using the command "java Project4 < test.txt", where test.txt contains your test data. This can save a lot of time over typing in coordinates manually every time.
• Some double type variables are required in this project because of the trigonometry functions. In general, use integer arithmetic whereever possible. Coordinates, in particular will always be rounded down to an integer. This is equivalent to having the treasure map already marked with a precise grid of paces; when a treasure hunter completes a direction in the middle of a grid square, he or she takes a fraction of a pace to stand on the corner of the grid square closest to the origin (0,0,0).
• Bearing is cumulative -- you add the new bearing to the direction you are already facing. Declination is not; you start each new direction from horizontal.
• The Java math library contains methods Math.sqrt(), Math.sin(), and Math.cos to calculate square roots for the distance function, and trigonometric identities to decompose the coordinates. You can read further details of these methods on the Java API website online, or in your textbook.