Guest User

Untitled

a guest
Dec 10th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. // Rectangles.java
  2. // Shashank Raghavachari
  3. // Rectangles extends Polygons, but adds another variable and relevant methods
  4.  
  5. import TerminalIO.KeyboardReader;
  6.  
  7. //A subclass of Polygons just for rectangles
  8. public class Rectangles extends Polygons
  9. {
  10.     //Adding a new variable -- Determines if Rectangle object is square
  11.     private boolean isSquare;
  12.    
  13.     //non-default constructor
  14.     public Rectangles(double w, double h)
  15.     {
  16.         super(w,h);
  17.         if (w==h)
  18.         {
  19.             isSquare = true;
  20.         }
  21.     }
  22.    
  23.     //accessor method
  24.     public boolean getIsSquare()
  25.     {
  26.         return isSquare;
  27.     }
  28.    
  29.     public double getArea()
  30.     {      
  31.         return getWidth()*getHeight();
  32.     }
  33.    
  34.     public void displayInfo()
  35.     {
  36.         System.out.println("\n\nSHAPE INFO:");
  37.         System.out.println("The figure is a rectangle.");
  38.         System.out.println("It's a square? " + isSquare);
  39.         System.out.println("Area: " + getArea());
  40.         super.displayInfo();       
  41.     }                              
  42. }
Add Comment
Please, Sign In to add comment