Advertisement
therrontelford

Rectangle

Sep 15th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. /*  Telford
  2.  * September 14, 2017
  3.  * Rectangle class
  4.  */
  5. public class Rectangle {
  6.     private double base;
  7.     private double height;
  8.    
  9.     //construct a rectangle
  10.     public Rectangle() {
  11.         base = 1;
  12.         height = 1;
  13.     }
  14.    
  15.     //construct a rectangle with parameters
  16.     public Rectangle(double b, double h) {
  17.         base = b;
  18.         height = h;
  19.     }
  20.  
  21.     public void getHeight() {
  22.     return height;
  23.        
  24.     }
  25.     public void getBase() {
  26.         return base;
  27.        
  28.     }
  29.     public void setHeight(double h) {
  30.         height = h;
  31.        
  32.     }   public void setBase(double b) {
  33.         base = b;
  34.        
  35.     }
  36.     // write method to compute area
  37.     public double getArea() {
  38.         return base * height;
  39.     }
  40.     // write method to compute perimeter
  41.     public double getPerimeter() {
  42.         return 2 * base + 2 * height;
  43.     }
  44.  
  45.     // write a toString method which displays the object
  46.     public String toString(){
  47.         return " The area and perimeter of this rectangle is " + getArea() " and " + getPerimeter();
  48.     }
  49.  
  50.  
  51.  
  52.    
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement