import.awt.Rectangle;

public class AreaTester
{
	public static void main(String[] args)
	{
		Rectangle R = new Rectangle(5,6,7,8);
		System.out.print("w: ");
		int w = R.getWidth();
		System.out.println(box.getWidth());

		System.out.print("h: ");
		int h = R.getHeight();
		System.out.println(box.getHeight());
		int area = w*h;
		System.out.println("Area of Rectangle:"+ area);

	}
}

The above code gives error:<identifier> expected
import.awt.Rectangle;
^

Recommended Answers

Of course it does, because there is no ".awt.Rectangle" class. Check the class' package again.

Jump to Post

All 4 Replies

Of course it does, because there is no ".awt.Rectangle" class. Check the class' package again.

import java.awt.Rectangle;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class AreaTester
{
	public static void main(String[] args)
	{
		Rectangle R = new Rectangle(5,6,7,8);
		System.out.print("w: ");
		double w = R.getWidth();
		System.out.println(box.getWidth());

		System.out.print("h: ");
		double h = R.getHeight();
		System.out.println(box.getHeight());
		double area = w*h;
		System.out.println("Area of Rectangle:"+ area);

	}
}

Errors:
cannot find symbol
System.out.println(box.getWidth());
^
symbol: variable box
location: class AreaTester
cannot find symbol
System.out.println(box.getHeight());
^
symbol: variable box
location: class AreaTester
2 errors

The errors are pretty clear. The compiler can't find the variable 'box'. Can you?

Where's your declaration of the box variable?

Be a part of the DaniWeb community

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