Create a Rectangle class, which has the following members:
Type this must store whether the rectangle is a square or not
Length
Width
Area()
Perimeter()
You need to overload the constructor so the user can create both a rectangle, and a square (i.e., you only enter one value, which is the same for both length and width).
You must also overload the Area() and Perimeter() methods, since they will have different definitions for square and rectangle.
Area of Rectangle: $L \times W$
Perimeter of Rectangle: $2 \times (L + W)$
Area of Square: $L^2$ (you can use Math.Pow() here)
Perimeter of Rectangle: $4 \times L$
You must also create static methods that let you calculate the Perimeter and Area of any Length and Width values, without having to create an object first.
Assignment 6
Create a
Rectangle
class, which has the following members:Type
this must store whether the rectangle is a square or notLength
Width
Area()
Perimeter()
You need to overload the constructor so the user can create both a rectangle, and a square (i.e., you only enter one value, which is the same for both length and width).
You must also overload the
Area()
andPerimeter()
methods, since they will have different definitions for square and rectangle.You must also create
static
methods that let you calculate the Perimeter and Area of any Length and Width values, without having to create an object first.