Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

AreaTester - Rectangle object

843785Sep 5 2008 — edited Sep 5 2008
I'm trying to write an AreaTester program that constructs a Rectangle object and then computes and prints its area. So far, I have gotten here, but I don't know how to find the area. I have been stuck for an hour.
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class AreaTester
{
   int width, height;
   public static void main(String[] args)
   {
      Rectangle box = new Rectangle(12,12,4,4);

      // Print information about rectangle
      System.out.print("Width: ");
      System.out.println(box.getWidth());

      System.out.print("Height: ");
      System.out.println(box.getHeight());

      System.out.print("Area: ");
   }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 3 2008
Added on Sep 5 2008
6 comments
272 views