Hey there, I'll just give you a few pointers here:
public static double distance (double x1, double y1, double x2, double y2, double z, double y3, double x3)
{
y3 = (y2 - y1);
y3 = Math.pow(y3, 2);
x3 = (x2 - x1);
x3 = Math.pow(x3, 2);
z = Math.sqrt(y3 + x3);
return z;
}
}
This metod distance takes a ( double, double, double, double, double, double, double ), that's 7 doubles! A couple of points on this here:You only read in 4 in your program: x1, y1, x2, y2... where do z1 and z2 come from???
You call System.out.println( distance( z ) ); in your main method, you have no z variable, and you're only supplying one argument!
1. I'm taking it that y1 and y2 are the points on the circumference of the circle?? and x1 and x2 is the center of the circle. As you only read in 4 points in the circle, and these are the one's you are working on, you should have a method:
distance( double _x1, double _x2, double _y1, double _y2 )
{
//If you have a center and a point on the circumference of the triangle we use pythagoras theorem to calculate the radius, a = root( b^2 + c^2 )
//We'll define a new double rad for this
double rad = 0;
//Each side is equal to the x point - the y point
//It doesn't matter if the above returns a minus result as it is being squared.
rad = Math.sqrt( Math.pow( _x1 - _y1, 2 ) + Math.pow( _x2 - _y2, 2 ) );
return rad; //Return the radius
}
Notice that it's more streamline now! It can also simply be written as:
distance( double _x1, double _x2, double _y1, double _y2 )
{
return Math.sqrt( Math.pow( _x1 - _y1, 2 ) + Math.pow( _x2 - _y2, 2 ) );
}
Do what ever works for you, and ALWAYS ALWAY ALWAYS remember to indent and comment your code.
2. As distance now only takes 4 parameters it should be called as follows:
...
public static void main ( String [] args )
{
//Read yer points...
System.out.println( distance( x1, x2, y1, y2 ) );
}
...