COMP 2030SEF-Lab03-Interface
COMP 2030SEF-Lab03-Interface
Instructions
1. Download the lab materials from OLE and unzip it to your desktop.
[Part I] Example
Study the examples provided from the sample project with the order specified below:
InAnimal.java
- Animal (superclass: interface class)
- Rabbit (subclass)
- Snake (subclass)
1
iii. Create a class InterfaceShape, with details below:
a. Add a main method():
class InterfaceShape {
public static void main(String[] args) {
…
}
}
b. Add a new Square object mySquare and call the constructor method passing 3
as the parameter.
c. Call the appropriate methods to output the following:
---------- Capture Output ----------
[Square]
length: 3.0
perimeter: 12.0
iv. In class Square, which implements Shape and add details as below:
a. Add a method area() which returns the area value.
b. Add a method drawShape() [no returned value] which prints out a square
shape.
drawShape:
***
***
***
vi. Create a class Rectangle which implements Shape with details below:
a. Add an attributes width and height (double type)
b. Add a constructor method Rectangle(double aWidth, double aHeight)
c. Add a getter methods
d. Add a method perimeter() which returns the calculated perimeter value.
e. Add a method area() which returns the area value.
f. Add a method drawShape() [no returned value] which prints out a square
shape.
2
vii. In class InterfaceShape, add details below:
a. Add a new Rectangle object myRectangle and call the constructor method as
i.e. Rectangle(5, 2)
b. Call the appropriate methods to output the following:
---------- Capture Output ----------
[Rectangle]
Width: 5.0
Height: 2.0
perimeter: 14.0
area: 10.0
drawShape:
*****
*****
drawShape:
***
***
***
[Rectangle]
Width: 5.0
Height: 2.0
perimeter: 14.0
area: 10.0
drawShape:
*****
*****