0

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 :(

5
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by ajst
Featured Replies
  • you have to define RectangleBox of a Rectangle type or of Rectangle supper classes so either you write [CODE]Rectangle RectangleBox ;[/CODE] in line 10 or you write [CODE]Rectangle RectangleBox = new Rectangle(10, 20, 12, 15);[/CODE] in line 11 Read More

  • As naief pointed out, You have not specified the type of variable RectangleBox is. Every variable needs a type. [CODE] //type - variable name int a; double b; Rectangle rect;[/CODE] In your case, you want your RectangleBox variable to be of type Rectangle. Most naming conventions don't start variable names … Read More

  • 1

    [CODE] System.out.println("area = " + area); [/CODE] or you could do [CODE] System.out.print ("area = "); System.out.println (area); [/CODE] Both will achieve the same result. Read More

  • yes as ajst said (above) the reason why your area = did not print on the same line is because you put System.out.[I]println[/I] 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 … Read More

  • 1

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

1

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

Edited by naief: n/a

Comments
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{}

Edited by Akill10: n/a

0

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!

0

omg im an idiot.....

public class AeraTester

AERA does not equal AREA.

thanks guys, i'll up vote!

thread closed.

Edited by z00t: n/a

0

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?!

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

or
you could do

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

Both will achieve the same result.

Edited by ajst: typo

1

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

Edited by javanoob101: n/a

1

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.