*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rectangle error" Watch "Rectangle error" New topic
Author

Rectangle error

Walt Lee
Greenhorn

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:

// Rectangle.java:

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; }

}

// ClientProgram.java


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() );

mySquare.setHeight(10);

mySquare.setWidth(15);

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
Sheriff

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
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rectangle error
 
Similar Threads
inheritance problem
compareTo ( ) object
Beginner Question: Class Capabilities
How to fix error in Rectangle Class problem in Java?
drawRect method !!!