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
Which symbol shows an input?
LenaWriter [7]

Answer:

Document symbol

Explanation:

This symbol is shaped like a rectangle with its bottom side in a wave, and it is used to represent the input or output of a document. For instance, this symbol might be used to outline a document input, such as receiving an email or report.

hope it helps

mark me brainliest pls

8 0
3 years ago
Which part of project management involves determining the required materials?
oksian1 [2.3K]

Answer:

Resources I think because what you have all depends on resources which required money

PLZ CORRECT ME IF I AM Wrong please and thank you

Explanation:

8 0
3 years ago
Read 2 more answers
How does a Cloud-first strategy approach a client's migration to the Cloud?by removing outside ecosystem partners from the Cloud
belka [17]

Cloud-first strategies are <em>operating methods</em> wherein teams move all or most of their infrastructure to <em>cloud computing systems</em><em>  </em>such as Web Services, and the further discussion can be defined as follows:

  • It stores assets, including quest and <em>secure resources</em>, in the cloud rather than employing <em>physical resources</em> including such server clusters.
  • This approaches a client's migration to the <em>Cloud by integrating multiple services </em>together to serve the client's business needs.

Therefore, the final answer is "Last choice".

Learn more:

brainly.com/question/1256812

3 0
3 years ago
It’s illegal to hack into a system without authorization, but is it ethical for a gray-hat to hack into a system if the intent i
oksian1 [2.3K]

Answer:

Some hackers are smart about there hacking .. others have a a plot but didnt test there theory

Explanation:

8 0
3 years ago
In portrait mode, your camera will use what?
vesna_86 [32]

Answer:

A. A Smaller Aperture

Have A Good Day

3 0
3 years ago
Other questions:
  • A dmz is a subnet of _____________ accessible servers placed outside the internal network.
    10·1 answer
  • (Display nonduplicate words in ascending order)
    11·1 answer
  • Other side for bullying
    7·1 answer
  • What is a preemptive CPU scheduling algorithm? Give an example and explain.
    7·1 answer
  • Search the web to discover the 10 most common user-selected passwords, and store them in an array. Design a program that prompts
    7·1 answer
  • What is bigger 4 liters or one gallon
    13·1 answer
  • As discussed in the video, parallax measurements allow us to calculate distances to stars for which parallax is detectable. Supp
    14·1 answer
  • What is computer science ​
    5·1 answer
  • Select the best answer from the drop-down menu.
    14·2 answers
  • Give one of user responsibility of the internet you should follow in cyberethics.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!