Package it.unimi.di.prog2.s17
Class Rectangle
java.lang.Object
it.unimi.di.prog2.s17.Rectangle
- Direct Known Subclasses:
Square
A mutable class representing a rectangle with integer valued base and height.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRectangle
(int base, int height) Creates a rectangle of given base and height. -
Method Summary
-
Field Details
-
base
private int baseThe base of the rectangle. -
height
private int heightThe 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
-