Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using interface in Java. In this task, you will practice the interface in OOP. Please follow the below steps to finish the task. 1.
Using interface in Java. In this task, you will practice the interface in OOP. Please follow the below steps to finish the task. 1. Create a Shape interface which includes an area() and a constant variable PI inside the i 2. Create the classes Rectangle, Triangle, Circle, and Ellipse to find the area by implementing the interface Shape. You may need to declare the constructors with arguments and declare variables dim1, dim2 and PI. Dim1 and dim2 are dimensions of the respective shape. For example for a rectangle it is the length and breadth. Note that the formula to calculate the area of Ellipse is: PI*A*B where A and B are the semi-major axis of length and semi-minor axis of length. 3. In main(), create the objects for all classes and pass values to fields of constructors. Rectangle r = new Rectangle(9, 5);B Triangle t = new Triangle (10, 8); Circle c=new Circle (5,5); Ellipse e=new Ellipse (7,7); Square s=new Square (6,6); Shape figref; 4. Create a reference variable figref for the interface. 5. Using reference variable of class Shape, call the method area() of all the classes 6. Print the areas for all shapes.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started