Rectangle

Rectangle - public double getLength () { return length; }...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
public class Rectangle { // fields protected double length; protected double width; // constructors Rectangle ( ) { length = 5.0; width = 2.0; } Rectangle ( double len, double wid ) { length = len; width = wid; } Rectangle ( Rectangle rec ) { length = rec.getLength(); width = rec.getWidth(); } // accessors (getters and setters) public void setLength(double val) { length = val; }
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public double getLength () { return length; } public void setWidth (double val) { width = val; } public double getWidth() { return width; } // general methods public double area ( ) { double result; result = length * width; return result; } public double perimeter () { return (length+width)*2.0; } }...
View Full Document

Ask a homework question - tutors are online