Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Rectangles.java
- // Shashank Raghavachari
- // Rectangles extends Polygons, but adds another variable and relevant methods
- import TerminalIO.KeyboardReader;
- //A subclass of Polygons just for rectangles
- public class Rectangles extends Polygons
- {
- //Adding a new variable -- Determines if Rectangle object is square
- private boolean isSquare;
- //non-default constructor
- public Rectangles(double w, double h)
- {
- super(w,h);
- if (w==h)
- {
- isSquare = true;
- }
- }
- //accessor method
- public boolean getIsSquare()
- {
- return isSquare;
- }
- public double getArea()
- {
- return getWidth()*getHeight();
- }
- public void displayInfo()
- {
- System.out.println("\n\nSHAPE INFO:");
- System.out.println("The figure is a rectangle.");
- System.out.println("It's a square? " + isSquare);
- System.out.println("Area: " + getArea());
- super.displayInfo();
- }
- }
Add Comment
Please, Sign In to add comment