I'm trying to construct a rectangle & compute its area using the getWidth & getHeight methods.. but i cant figure out for to construct a freakin rectangle!! I keep getting the same error when i go to complie it.. no matter how hard i try :p

"Cannot find symbol"

import java.awt.Rectangle;

public class AeraTester

{

	public static void main(String[] args)

	{

	RectangleBox = new Rectangle(10, 20, 12, 15);

	System.out.println(RectangleBox.getWidth() );

	}

}

this is really amature.. but i still need help :(

you have to define RectangleBox of a Rectangle type or of Rectangle supper classes
so either you write

Rectangle RectangleBox ;

in line 10
or you write

Rectangle RectangleBox = new Rectangle(10, 20, 12, 15);

in line 11

commented: quick reply & solved my problem. thx! +1

As naief pointed out, You have not specified the type of variable RectangleBox is. Every variable needs a type.

//type - variable name
int a;
double b;
Rectangle rect;

In your case, you want your RectangleBox variable to be of type Rectangle.
Most naming conventions don't start variable names with a capital letter either. You would start with lowercase, then if there is another word, capitalise that.

Rectangle rectangleBox;

Class declarations normally use upper-case.

class MyClass{}

okay thanks guys!!! i gave my variable a type & i am no longer getting that error.... however, now when i go to compile my program, i get this error!

AreaTester.java:3: class AeraTester is public, should be declared in a file named AeraTester.java
public class AeraTester
^

I dont know why i am getting this error such that, i have my program saved as AreaTester.java

UGH!

omg im an idiot.....

public class AeraTester

AERA does not equal AREA.

thanks guys, i'll up vote!

thread closed.

crap, one more problem guys:

import java.awt.Rectangle;



public class AreaTester

{

	public static void main(String[] args)

	{

	Rectangle box = new Rectangle(10, 20, 12, 15);

	double area = (box.getWidth()*box.getHeight());

	System.out.println ("area = ");
	System.out.println (area);	
	}

}

I want to print area = area on the same line. how do i do that?!

System.out.println("area = " + area);

or
you could do

System.out.print ("area = ");
System.out.println (area);

Both will achieve the same result.

yes as ajst said (above)

the reason why your area = did not print on the same line is because you put System.out.println instead of System.out.print. The println command adds a line of space. typing in print instead of println on the other hand does not add a space. (not sure if you were told that but you know now!)

hope this helps

Yea sorry I should of added an explanation, but javanoob101 did it for me :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.