• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Rectangle error

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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() );

}

}
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Whatever. Here's a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic