Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: Get hands-on experience on Java abstract classes and interfaces. Understand polymorphism and dynamic binding. Tasks: In Lab 8 we made a class Cube that

image text in transcribed

Objectives: Get hands-on experience on Java abstract classes and interfaces. Understand polymorphism and dynamic binding. Tasks: In Lab 8 we made a class Cube that inherits the class Rectangle. In this lab, we will make an abstract class Shape and an interface Drawable. The Shape class is the super class of Rectangle and Cube. Both Rectangle and Cube classes implement the Drawable interface. Create a project called BCS345Lab9. Copy Rectangle. java and Cube. java from Lab 8 and place them in the src directory of the new project 1. Create an abstract class called Shape which includes an abstract method getArea. 2. Define the getArea method in the Rectangle class (We've done it 3. Override the getArea method in the Cube class (area of a cube is its surface area) 4. Define the interface Drawable which includes a method drawable. 5. Define the drawable method in the Rectangle class to display a message "Draw a rectangle" 6. Define the drawable method in the Cube class to display a message "Draw a cube" 7. In the driver program BCS345Lab9.java, create a Shape array of size 4 and instantiate it with the following objects: A Rectangle object with length 10 and width 20, A Rectangle object with length-4 and width-5 (to test data validation), A Cube object with length 2, width 3, and height 4 A Cube object with length 11, width 12, and height-13 Use a loop to call the area method to display the areas of the above objects. Explain the output. Use the similar code in 7, declare a Drawable array of size 4 and instantiate it with the same objects as in 7. In the loop call the drawable method with each object. Explain the output 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions