You will also get a bit more practice programming to an interface.
Shape
InterfaceShape
with the following behavior (method names are in ()'s):
perimeter
)
area
)
numSides
)
isQuadrilateral(
)
isEquilateral
)
int
or boolean
Rectangle
ClassShape
-implementing class named Rectangle
.
ShapeApp
ShapeApp
with the following output Assume ShapeApp
invoked by RectangleApp
).
Assume ShapeApp
has the static method demo
that accepts the Shape
it will be 'demo'ing, and RectangleApp
call demo
with a Rectangle
object it creates.
--- Shape demo for Rectangle --- a rectangle with a width of 4 and a height of 3 perimeter: 14 area: 12 isQuadrilateral: true isEquilateral: false
Rectangle
)
getClass
(of class Object
and thus available to all classes) returns an object of type Class
.
Performing a System.out.println on this object (i.e., invoking its toString
method) prints out the name of the class prefixed with the word
'class' (e.g., class Rectangle
). The getName
method of Class
returns simply the name of the class
(e.g. Rectangle
)
toString
result).
RectangleApp
RectangleApp
that invokes ShapeApp
with a Rectangle
object. Assume ShapeApp
invoked by RectangleApp
).
Assume ShapeApp
has the static method demo
that accepts the Shape
it will be 'demo'ing, and RectangleApp
call demo
with a Rectangle
object it creates.
RectangleApp
.
Square
ClassSquare
class: independent, composition, and inheritance. They are independent of each other; feel free
to implement in whatever order you wish.
In 6.2 below, you are asked to code a SquareApp
that invokes ShapeApp
(using dependency injection). This app can then be used in 6.3 and 6.4 as well.
Square
ClassShape
named Square
. The class should not use or inherit from Rectangle
.
SquareApp
app that invokes ShapeApp
.
Here is the output for this (i.e., independent) implementation of Square
:
--- Shape demo for Square --- an independently implemented square with a side of 3 perimeter: 12 area: 9 isQuadrilateral: true isEquilateral: true
toString
result for each of the implementations is different
SquareApp
app so you can execute an app using your Square
class. You will use this app in the next two parts as well.
Square
and SquareApp
classes will be presented as separate labs (6.2.1 and 6.2.2). Labs 6.3-6.4 will ask for the Square
class only.
Square
ClassShape
named Square
. The class should use composition using the Rectangle
class.
Here is the output for SquareApp
for this implementation of Square
:
--- Shape demo for Square --- a square composed of a rectangle with a width of 3 and a height of 3 perimeter: 12 area: 9 isQuadrilateral: true isEquilateral: true
Square
ClassShape
named Square
that inherits from Rectangle
.
Here is the output for SquareApp
for this implementation of Square
:
--- Shape demo for Square --- a square inherited from a rectangle with a width of 3 and a height of 3 perimeter: 12 area: 9 isQuadrilateral: true isEquilateral: true