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
How desktop case or chassis designed?, material and steps?​
MariettaO [177]

They may require things such as plastic cut outs and glass depending if you want to be able to have a window to look into the pc. Some cases are 3D Printed although they have to be joined by screws at the end due to the fact that one whole print can take over a week and then it has to be well doesn't but looks better when sanded.

3 0
1 year ago
5 of 10
DaniilM [7]

Answer:

what

Explanation:

3 0
2 years ago
To complete a forensic disk analysis and examination, you need to create a ____.
just olya [345]
<span>To complete a forensic disk analysis and examination, you need to create a </span>report.
8 0
3 years ago
Why are there more producers then consumers?​
Ivanshal [37]

Answer:

because producer can make their own food

6 0
3 years ago
Read 2 more answers
Which folder(s) are commonly used in the Navigation Pane of Outlook? Check all that apply.
tensa zangetsu [6.8K]

The Navigation Pane in Outlook is used to switch between the different areas of Outlook,such as Mail, Calendar, Contacts, Tasks, and Notes., the Navigation Pane displays the folders within the view you are working with. The following folders are commonly used in the Navigation Pane in Outlook:

Inbox

Sent Items

Deleted Items

They are most commonly included in the Favorites.

6 0
3 years ago
Other questions:
  • Need answers for 11&amp;12. Due today. Thanks.
    14·1 answer
  • Write a function called printbackwards() that will work with a c++ string
    14·1 answer
  • A cell reference that has only one $ is referred to as a(n) ____ cell reference. alternative mixed relative absolute
    7·1 answer
  • Trisha is looking for a new table style. What is the fastest way for her to preview how different styles in the gallery would lo
    13·1 answer
  • The ____________ is a wildcard character that is used to search for an unknown single character.
    6·1 answer
  • When using the red / yellow / green method to present status of a project, yellow can mean which of the following? A. There are
    5·2 answers
  • HURRY UP !!!!!!’<br> Each packet is addressed to the recipient's .
    8·1 answer
  • Deciding whether to explode a process further or determine that it is a functional primitive is a matter of experience, judgment
    8·1 answer
  • can you give me a tip to fix my SIM card becuaus when i put it on my phone it has no signal , can anyone fix this , thank you.​
    9·2 answers
  • Which of the following correctly orders the units of measure from least to greatest?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!