Class Rectangle

java.lang.Object
it.unimi.di.prog2.s17.Rectangle
Direct Known Subclasses:
Square

public class Rectangle extends Object
A mutable class representing a rectangle with integer valued base and height.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    The base of the rectangle.
    private int
    The height of the rectangle.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Rectangle(int base, int height)
    Creates a rectangle of given base and height.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the base of the rectangle.
    void
    base(int base)
    Sets the base of the rectangle.
    int
    Returns the height of the rectangle.
    void
    height(int height)
    Sets the height of the rectangle.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • base

      private int base
      The base of the rectangle.
    • height

      private int height
      The height of the rectangle.
  • Constructor Details

    • Rectangle

      public Rectangle(int base, int height)
      Creates a rectangle of given base and height.
      Parameters:
      base - the base of the rectangle.
      height - height of the rectangle.
      Throws:
      IllegalArgumentException - if base or height are negative.
  • Method Details

    • base

      public int base()
      Returns the base of the rectangle.
      Returns:
      the base of the rectangle.
    • base

      public void base(int base)
      Sets the base of the rectangle.
      Parameters:
      base - the new base of the rectangle.
      Throws:
      IllegalArgumentException - if base is negative.
    • height

      public int height()
      Returns the height of the rectangle.
      Returns:
      the height of the rectangle.
    • height

      public void height(int height)
      Sets the height of the rectangle.
      Parameters:
      height - the new height of the rectangle.
      Throws:
      IllegalArgumentException - if height is negative.
    • toString

      public String toString()
      Overrides:
      toString in class Object