1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
seraphim [82]
3 years ago
9

4. Write an interface ObjectWithTwoParameters which has a method specification: double area (double d1, double d2) which returns

the area of a particular object. Write three classes RectangleClass, TriangleClass, and CylinderClass which implement the interface you created. Also, write a demo class which creates objects of RectangleClass, TriangleClass, and CylinderClass and call the corresponding methods
Computers and Technology
1 answer:
il63 [147K]3 years ago
8 0

Answer:

The java program for the given scenario is as follows.

import java.util.*;

//interface with method area

interface ObjectWithTwoParameters

{

double area (double d1, double d2);

}

class RectangleClass implements ObjectWithTwoParameters

{

//overriding area()

public double area (double d1, double d2)

{

return d1*d2;

}

}

class TriangleClass implements ObjectWithTwoParameters

{

//overriding area()

public double area (double d1, double d2)

{

return (d1*d2)/2;

}  

}

class CylinderClass implements ObjectWithTwoParameters

{

public double area (double d1, double d2)

{

return ( 2*3.14*d1*d1 + d2*(2*3.14*d1) );

}

}

public class Test

{

public static void main(String[] args)

{

//area displayed for all three shapes

ObjectWithTwoParameters r = new RectangleClass();

double arear = r.area(2, 3);

System.out.println("Area of rectangle: "+arear);

ObjectWithTwoParameters t = new TriangleClass();

double areat = t.area(4,5);

System.out.println("Area of triangle: "+areat);

ObjectWithTwoParameters c = new CylinderClass();

double areac = c.area(6,7);

System.out.println("Area of cylinder: "+areac);

}

}

OUTPUT

Area of rectangle: 6.0

Area of triangle: 10.0

Area of cylinder: 489.84

Explanation:

1. The program fulfils all the mentioned requirements.

2. The program contains one interface, ObjectWithTwoParameters, three classes which implement that interface, RectangleClass, TriangleClass and CylinderClass, and one demo class, Test, containing the main method.

3. The method in the interface has no access specifier.

4. The overridden methods in the three classes have public access specifier.

5. No additional variables have been declared.

6. The test class having the main() method is declared public.

7. The area of the rectangle, triangle and the cylinder have been computed as per the respective formulae.

8. The interface is similar to a class which can have only declarations of both, variables and methods. No method can be defined inside an interface.

9. The other classes use the methods of the interface by implementing the interface using the keyword, implements.

10. The object is created using the name of the interface as shown.

ObjectWithTwoParameters r = new RectangleClass();

You might be interested in
To save a new copy of an existing database, a user can open the original database and select ________ from the file tab.
Yuri [45]
And select copy from the file tab.
6 0
3 years ago
Which sql server 2012 edition is targeted at hosted, internet-facing deployment?
Mice21 [21]
<span>The Web version will work for this type of need. This version runs at a slightly lesser capability than the full version, but will still perform many of the advanced functions of SQL Server. The processor and RAM utilizations are a bit less than the maximum provided in other versions.</span>
7 0
3 years ago
Review the sentences about the accounting problem statement. Using the drop-down menu, identify if the sentence is part of the v
Tju [1.3M]
Issue
Method
Issue
Vision
8 0
3 years ago
Whats the best strategy for avoiding ATM fees?
natulia [17]
You hack the atm that's how
3 0
3 years ago
Read 2 more answers
Microsoft word 365 allows cells to be split into how many columns
Bogdan [553]

Answer:

Microsoft word 365 allows two columns

8 0
3 years ago
Read 2 more answers
Other questions:
  • Jennifer’s company currently uses Windows Active Directory to provide centralized authentication, authorization, and accounting
    7·1 answer
  • The incident results in huge losses of revenue as a result their mobile app service is withdrawn. Investigators discovered a vul
    5·1 answer
  • Plz help me of this answer<br><br><br>language:python​
    7·2 answers
  • A(n) ______ system is a set of programs that coordinates all the activities among computer or mobile device hardware. a. managem
    10·1 answer
  • ________ is a model of computing in computer processing, storage, software, and other services which are provided as a shared po
    9·1 answer
  • Design a circuit that has a 3-bit binary input B2, B1, B0 (where B2 is most significant bit and B0 is least significant bit) and
    14·1 answer
  • Write a program that calculates the total amount of a meal purchased at a restaurant by a customer. The program should ask the u
    15·1 answer
  • The bubble sort algorithm sorts using what technique?
    14·1 answer
  • What will be the index of leaf node in a right-skewd binary tree with height =7,where every parent has at most one child?​
    15·1 answer
  • All of the following are true about data science and big data except: a.Digital data is growing at the rate of 2.5 quintillion b
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!