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
Why ues storage unit?​
Jet001 [13]

Huh? I don’t understand your question... please be more specific so we can help you

6 0
2 years ago
Unit testing:_________. A. provides the final certification that the system is ready to be used in a production setting. B. incl
NARA [144]

Answer:

Option (C) is the correct option to the following question.

Explanation:

The following option is correct because the unit testing is the process of testing a single unit of software at a time, which means the testing of each and every program separately.

In simple words, Unit testing a process of testing in which the developer executes the single method or a function, statements or loop in the program of the software to checking is it working fine or not.

7 0
2 years ago
Releasing refrigerant R-12 into the atmosphere is a criminal offense
nevsk [136]
I'm guessing you want a yes or no... I think yes.
8 0
3 years ago
Read 2 more answers
Assume that you have 22 slices of pizza and 7 friends that are going to share it (you've already eaten). There's been some argum
xz_007 [3.2K]

Answer:

In Python:

numberOfWholeSlices = int(22/7)

print(numberOfWholeSlices )

Explanation:

For each friend to get a whole number of slices, we need to make use of the int function to get the integer result when the number of slices is divided by the number of people.

So, the number of slice is: 22/7

In python, the expression when assigned to numberOfWholeSlices  is:

numberOfWholeSlices = int(22/7)

Next, is to print the calculated number of slices

print(numberOfWholeSlices )

4 0
3 years ago
The correct or acceptable way of communicating on the internet is known as
stepladder [879]
I want to say e-mail.

8 0
3 years ago
Other questions:
  • What exactly is a byte? A byte is a term that is short for binary digit. 8 bytes hold about one letter, one number, or one speci
    10·1 answer
  • To calculate the chapter from which you must solve the programming exercise, divide the integer number representing your student
    10·1 answer
  • Look at the four schematic symbols shown in the figure above. Each of the symbols is labeled with a number. Which of the followi
    5·2 answers
  • Why is it important to know much time you spend on task
    8·1 answer
  • Assignment 3: Chatbot
    11·2 answers
  • Which of the following is NOT contained on the Slide Show toolbar?
    11·2 answers
  • Which is a false statement considering copyright law?
    13·2 answers
  • Reply emailing a student who is asking about audio materials​
    6·2 answers
  • Reflection about information technology​
    11·1 answer
  • You have been asked to advise a group of several universities who want to combine research efforts and store data in the cloud.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!