This assignment has me completely confused.
How do I begin this????
How to set the bearings, etc. as ints?
We were given this:
package treasureHunt;
import java.util.Scanner;
public class Coordinate {
private int x;
private int y;
private int z;
public Coordinate()
{
x = 0;
y = 0;
z = 0;
}
public Coordinate (int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
public int getX () {return x; }
public int getY () {return y; }
public int getZ () {return z; }
public void setX(int x) {this.x = x; }
public void setY(int y) {this.y = y; }
public void setZ(int z) {this.z = z; }
public void print()
{ System.out.println("(" + x +"," + y +"," + z + ")" );
}
public void read (Scanner keyboard)
{
System.out.println("Please enter a list of tripples (distance, bearing, declination):");
x = keyboard.nextInt();
y = keyboard.nextInt();
z = keyboard.nextInt();
}
public double distanceFrom(int x2, int y2, int z2)
{
int dx = (x2 - x);
int dy = (y2 - y);
int dz = (z2 - z);
double distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
return distance;
}
public double distanceFrom(Coordinate c)
{
int dx = (c.x - this.x);
int dy = (c.y - this.y);
int dz = (c.z - this.z);
double distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
return distance;
}
public boolean equals(Coordinate c)
{
return (c.x == this.x) && (c.y = this.y) && (c.z == this.z);
}
// 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.) I want to write 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 inter- preted 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 dec- lination of 45 degrees would be up a steep hill; -5 degrees would be a gentle downs- lope; 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.