Advertisement
advictoriam

Untitled

Jan 31st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. /**
  2.    A square is a rectangle whose sides have the same length.
  3. */
  4. public class Square
  5. {
  6.    private double length;
  7.    
  8.    /**
  9.       Constructs a square with a given side length.
  10.       @param sideLength the length of each side
  11.    */  
  12.    public Square(double sideLength)
  13.    {
  14.       length = sideLength;
  15.    }
  16.    
  17.    /**
  18.       Returns the area of this square.
  19.       @return the area
  20.    */
  21.    public double area()
  22.    {
  23.       return length * length;      
  24.    }
  25.    
  26.    /**
  27.       Grows the side length of this square.
  28.       @param percentage the percentage by which to grow the square (for example,
  29.       10 if the square is to be grown by 10%).
  30.    */
  31.    public void grow(double percentage)
  32.    {
  33.       length *= (1 + (percentage / 100));        
  34.    }
  35.  
  36.    // This method is used for checking your work. Do not modify it.
  37.  
  38.    public static double check(double s, double p)
  39.    {
  40.       Square sq = new Square(s);
  41.       sq.grow(p);
  42.       return sq.area();
  43.    }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement