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
50 points for each person brainless goes to the best answer
wolverine [178]

Technical writing is writing that is done for the purpose of educating, informing or directing someone on how to do something. Technical writing is significantly different than other types of writing such as narrative, because technical writing is intended to impart to the reader some specific skill or ability. Technical writing isn't for everyone. It is often very detail-oriented and usually involves writing within fields where some advanced knowledge is required. When given a technical writing assignment, it also must be approached in a certain way in order for you to be successful. but i would have to go with c- e commerce

6 0
3 years ago
Read 2 more answers
Which of the following resources is an example of a web-based application?
kompoz [17]
The answer will be google docs since it depends on a web and its an application. hope it helps

3 0
3 years ago
What security weaknesses/vulnerabilities exist in Wireless local area network device hardware and software?
AfilCa [17]

Answer:

Explanation:

There are many weaknesses/vulnerabilities, some of which are the following...

Default Network Hardware, many individuals will go out and buy a new router and install it in their home. These devices come with a preset configuration including a preset security password which is many times a default password used for every router of the same model. This can be easily obtained by anyone who can then access the network.

Access Point hacking, an experienced individual can use a packet sniffer to detect the SSID that is frequently sent from the router in order to create an access point to be able to access the network.

WEP encryption is another vulnerability. These are very low security passwords that can be cracked using different software in a short period of time.

These are some of many vulnerabilities that wireless local networks have, but there are also many precautions and security measures that can be taken to prevent them.

7 0
2 years ago
A wireless _____ area network is designed for devices in an area up to 50 kilometers (31 miles) using rf or infrared transmissio
gavmur [86]
Metropolitan. Hope this helps!
7 0
2 years ago
How often should administrators and network users be required to change their password?
Sergeu [11.5K]
Once every 3 month's
8 0
3 years ago
Other questions:
  • A. When executing System.out.println(a1), the toString() method in the Object class is invoked.
    14·1 answer
  • A drivers touches a cars steering wheel on a hot day which term refers to the way heat is transferredd to the drivers hand
    6·2 answers
  • Airbags only absorb the _____ impact in a crash. initial final mid-stage smallest
    13·1 answer
  • What are the benefits of using a multiview sketch to communicate a design?
    11·1 answer
  • Create a structure named planet This structure will contain distance from Earth as an integer Atmosphere, language, people and p
    8·1 answer
  • In JAVA,
    10·1 answer
  • -The following type of Access form allows to see multiple records in an Excel-like arrangement of data fields:
    14·1 answer
  • The language C was originally developed by​
    11·2 answers
  • How to print wireless from laptop to samsung printer?
    6·2 answers
  • . prevalence of coronary artery disease in patients with isolated aortic valve stenosis. br heart j. 1984;51:121–4.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!