Start New Discussion within our Software Development Community

A program similar to CircleClass.java which defines a rectangle object. ClientProgram.java is the driver program for the Rectangle.java file.

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

While pursuing a Computer Science degree, I founded DaniWeb.com, an online community for developers and IT professionals. I coded the backend platform from the ground up and I also do all of the advertising sales and SEO. I'm a super-geeky programmer with a passion for Internet marketing.

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.