
Originally Posted by
Saltine
Code:
double r1.area = width*height;
System.out.println("Area = " + area);
is where your problem lies.
you dont need to re-declare r1.area as a double, as i assume it is a public field in the Rectangle class already. Now on the second line, you attempted to print a local variable named area which does not exist. You need to print r1.area, as area is stored in that object of the Rectangle class, not your local class.
it doesn't matter, Rectangle r1 and dobule r1 are two different variables, Java can differ an object and a double even if they use the same name.
his problem is that getWidth() and getLength() are not voids, but doubles (assuming they are doubles and not integers, else he would've {int area}), therefore he must have done
Code:
public static void main(String[] args)
{
Rectangle r1 = new Rectangle (10, 20, 30, 50);
double width= r1.getWidth();
double height= r1.getHeight();
double area = width*height;
System.out.println("Area = " + area);
}
sticking to his way of writing this, of course it's best to keep it with less variables.