Answered step by step
Verified Expert Solution
Question
1 Approved Answer
John is a final year student of the SCOPE department at VIT - AP University. The placement season is on and he will be sitting
John is a final year student of the SCOPE department at VITAP University. The placement
season is on and he will be sitting for the campus interviews. He and his friend Bob were
brushing up their Java concepts one day before the placements. Bob asked John to write a Java
program that utilizes the concept of an interface. Alice created an interface named Shape with
two methods as depicted below:
public double periTriangle double side double side double side; with three double
arguments. The method returns the perimeter of the triangle.
public double periRectangle double side double side; with two double arguments.
The method returns the perimeter of the rectangle.
John attended Object Oriented Programming lectures at VITAP and he knows that he cannot
instantiate the Shape interface and so cannot access the member functions of the Shape
interface. So he created a class named Perimeter and is public that implements an interface
Shape. The Perimeter class provide the implementation calculates the perimeter of both the
methods of an interface and the perimeter is returned from the respective methods. In
Perimeter class, declare instance variables namely double side double side double side
and double perimeter and take the values of the variables double side double side double
side from the user. Create an object of the Perimeter class and access the instance methods
periTriangle and periRectangle. NOTE: For calculating the perimeter of a triangle use
the formula, perimeter side side side and for calculating the perimeter of a
rectangle use the formula perimeter side side
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