Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rectangle error

 
Walt Lee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I run the program and it ran fine,

What the error are you facing, analyze the stack or post it.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic