Tue Oct 26, 2010 1:35 am
/**
* Changes the distance between the two points
*/
public void distanceTo(double xPosition, double yPosition)
{
}
Wed Nov 03, 2010 3:57 pm
import java.lang.Math;
public class xPoint {
/**
* Makes the class executable
*/
public static void main(String[] args) {
xPoint p1 = new xPoint(5, 7);
xPoint p2 = new xPoint(8, 4);
System.out.println("Distance = " + p1.distanceTo(p2));
}
/**
* Private member containing the x coordinate
*/
private double x;
/**
* Private member containing the y coordinate
*/
private double y;
/**
* Method to compute the distance to another xPoint instance
* @param xPosition
* @param yPosition
*/
public xPoint(double xPosition, double yPosition) {
x = xPosition;
y = yPosition;
}
/**
* Method to compute the distance to another xPoint instance.
* @param other Instance to compute distance to.
* @return Distance between the current instance of xPoint and other.
*/
public double distanceTo(xPoint other) {
return Math.sqrt(Math.pow(x - other.x, 2) + Math.pow(y - other.y, 2));
}
}
Distance = 4.242640687119285
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.