Program not working - help?

So this is one of the practice questions for my computer science exam tomorrow. For some reason, whatever numbers I enter, the result comes up with this:

Quote:

Enter y2:

5

Enter y1:

2

Enter x2:

4

Enter x1:

2

The solution to the equation (y2-y1) / (x2 - x1) is NaN.

Why is the answer always NaN? Someone tell me what I'm doing wrong? Here is the code:

Code Java:

import java.io.*;
class questionone
{
public static void main (String [] args) throws IOException
{
InputStreamReader inStream = new InputStreamReader (System.in);
BufferedReader stdin = new BufferedReader (inStream);
double y2;
double y1;
double x2;
double x1;
System.out.println ("Enter y2: ");
y2 = Double.parseDouble (stdin.readLine ());
System.out.println ("Enter y1: ");
y1 = Double.parseDouble (stdin.readLine ());
System.out.println ("Enter x2: ");
x2 = Double.parseDouble (stdin.readLine ());
System.out.println ("Enter x1: ");
x1 = Double.parseDouble (stdin.readLine ());
Calculations calculate = new Calculations (x1, x2, y1, y2);
System.out.println (calculate.receive());
}
}
class Calculations
{
double x1;
double x2;
double y1;
double y2;
Calculations (double x1, double x2, double y1, double y2)
{
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
double numerator = y2 - y1;
double denominator = x2 - x1;
double solution = numerator / denominator;
String receive ()
{
return ("The solution to the equation (y2-y1) / (x2 - x1) is " + solution + ".");
}
}

Thanks

Re: Program not working - help?

The variables used in the calculations have not been assigned values when they are used in the expressions.

Re: Program not working - help?

So what could I do to make it work?

Re: Program not working - help?

Use the values passed to the constructor in the expressions that are used to compute and assign values to the variable that is displayed in the receive() method.

The current code uses the variables BEFORE they are given values in the constructor.

Re: Program not working - help?

I got it working. Thanks for the help!

Re: Program not working - help?

Post your wwwwwwworkin' code for those who might have your same problem