Rectangle

Rectangle - } // accessors (getters and setters) public...

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

View Full Document Right Arrow Icon
public class Rectangle { // fields private double length; private double width; // constructors Rectangle ( ) { // override the default constructor length = 5.0; width = 2.0; } Rectangle ( double len, double wid ) { // alternate construtor // you can specifiy the initial length, width length = len; width = wid; } Rectangle ( Rectangle rec ) { // alternate construtor // new one has same dimensions as the one passed in length = rec.getLength(); width = rec.getWidth();
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } // accessors (getters and setters) public void setLength(double val) { length = val; } 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

This note was uploaded on 11/30/2009 for the course COMP 110 taught by Professor Stotts during the Spring '08 term at UNC.

Ask a homework question - tutors are online