This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Rectangle error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rectangle error" Watch "Rectangle error" New topic

Rectangle error

Walt Lee

Joined: Oct 20, 2007
Posts: 4
It is a begging program I know, but getting an error that I can't figure out what is wrong with the line. Still hoping I did this program correctly per instructions:


package rectangle;

public class Rectangle


private double width = 1;

private double height = 1;

private static String color = "white";

public Rectangle() { }

public Rectangle(double w, double h, String c)


width = w;

height = h;

color = c;


public double getWidth() { return width; }

public void setWidth(double w) { width = w; }

public double getHeight() { return height; }

public void setHeight(double h) { height = h; }

public static String getColor() { return color; }

public static void setColor(String c) { color = c; }

public double findArea() { return height * width; }



package rectangle;

public class ClientProgram


public static void main(String args[])


Rectangle mySquare = new Rectangle(5, 5, "green");

System.out.print("\n Height = " + mySquare.getHeight() );

System.out.print("\n Width = " + mySquare.getWidth() );

System.out.print("\n Color = " + mySquare.getColor() );



System.out.print("\n\n Height = " + mySquare.getHeight() );

System.out.print("\n Width = " + mySquare.getWidth() );

System.out.print("\n Area = " + mySquare.findArea() );


Huzefa Zohaib
Ranch Hand

Joined: Nov 21, 2001
Posts: 40
I run the program and it ran fine,

What the error are you facing, analyze the stack or post it.
marc weber

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Walt Lee:
...getting an error that I can't figure out what is wrong with the line...

It seems to compile and run fine for me as well. As Huzefa suggested, please post the exact error you are receiving.

(My guess is that the package is not being used correctly. So it might help if you also tell us what your directory structure is for these files, and exactly what you're entering at the command prompt.)

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
It is sorta covered in the JavaRanch Style Guide.
subject: Rectangle error
jQuery in Action, 3rd edition