Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Telford
- * September 14, 2017
- * Rectangle class
- */
- public class Rectangle {
- private double base;
- private double height;
- //construct a rectangle
- public Rectangle() {
- base = 1;
- height = 1;
- }
- //construct a rectangle with parameters
- public Rectangle(double b, double h) {
- base = b;
- height = h;
- }
- public void getHeight() {
- return height;
- }
- public void getBase() {
- return base;
- }
- public void setHeight(double h) {
- height = h;
- } public void setBase(double b) {
- base = b;
- }
- // write method to compute area
- public double getArea() {
- return base * height;
- }
- // write method to compute perimeter
- public double getPerimeter() {
- return 2 * base + 2 * height;
- }
- // write a toString method which displays the object
- public String toString(){
- return " The area and perimeter of this rectangle is " + getArea() " and " + getPerimeter();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement