Question: Create 2 interfaces: Shape and Printable and you will modify the classes Rectangle, Square, IsoscelesRightTriangle, and Circle so that they implement one or both of

Create 2 interfaces: Shape and Printable and you will modify the classes Rectangle, Square, IsoscelesRightTriangle, and Circle so that they implement one or both of the interfaces. In addition you will create a class called InterfaceApp (different from InheritanceApp). This class includes the main method and demonstrates the polymorphic behavior of interfaces.

Declare the interfaces according to the UML diagrams:

Interface Shape:

Interface Printable:

perimeter .. returns the perimeter of the shape area .. returns the area of the shape

print ... prints the outline of the shape with small circles (see output) within a line the stars are always separated by a single space (blank) The rectangle is printed with the length on the x-axis (more wide than high) In case of the triangle the right angle is on the bottom left ( see output ) The output produced by the print method needs to reflect the actual field

values

CSIS-1410

Modify the four shape classes Rectangle, Square, IsoscelesRightTriangle, and Circle so that

all of them are a Shape

all except Circle are a Printable

Class InterfaceApp: This class include the main method.

All arguments passed to the constructors are hard-coded in the main method ( no user input)

Create an array of the interface type Shape and initialize it with two instances of Rectangle, Square, IsoscelesRightTriangle, and Circle ( a total of 8 shapes ) The rectangles have the sizes 6x3 and 5x4

The squares have the sides 4 and 3 The triangles have the leg sizes 5 and 3 The circles have the radii 7 and 2

Print the title Shape Array: and underline it with dashes

Loop though all the elements of the array.

For each of the array elements do the following:

print the shape (toString)

print the perimeter

print the area

if the shape is printable, print the shape Hint: use instanceof to find out whether a shape is printable

print a new line to structure the output The output should look like the output provided on the right

Video:

Output:

Shape Array: ----------- Rectangle(6x3) Perimeter: 18.0 Area: 18.0 ooooo o oo ooooo o

Rectangle(5x4) Perimeter: 18.0 Area: 20.0 oooo o oo oo oooo o

Square(4) Perimeter: 16.0 Area: 16.0 ooo o oo oo ooo o Square(3) Perimeter: 12.0 Area: 9.0 oo o oo oo o IsoscelesRightTriangle(5) Perimeter: 17.1 Area: 12.5 o oo oo oo oooo o IsoscelesRightTriangle(3) Perimeter: 10.2 Area: 4.5 o o o o o o

Circle(7) Perimeter: 44.0 Area: 153.9 
Circle(2) Perimeter: 12.6 Area: 12.6 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!