Click here to Skip to main content
15,742,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Updated 24-Feb-15 16:26pm
Sergey Alexandrovich Kryukov 24-Feb-15 21:30pm    
Your approach goes in wrong direction even before starting programming:

1) All your "question" is reduced to the fact that you are "completely confused". You are not even trying to ask questions, nothing real. Confused with what?

2) You somehow don't understand that "how do I begin" is not a constructive question. There could be millions points where to start, so what? This is not a key.

So, unfortunately, even though I tend to believe that you can get some help, your post looks under-qualified for the forum question. We generally answer more or less reasonable question, only in special cases give some general recommendations, only if some members feel interested to do so.

What have you tried so far? This is the first thing you need to think at. And then you can discuss detail. What goes wrong? What should behave in one way but behaves differently? And so on. "Completely confused" can be handled in some cases, but generally, this is not our genre, sorry.

Pandu Rang 24-Feb-15 23:41pm    
So what problem you facing in above program?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900