Question

# A line on a plane can be represented by coordinates of the two-end points p1 and p2 as p1(x1,y1) and p2(x2,y2).

A super class Plane is defined to represent a line and a subclass Circle to find the length of the radius and the area of circle by using the required data members of super class.

Some of the members of both the classes are given below:

Classname:Plane

Data members/instance variables:

x1:to store the x-coordinate of the first end point

y1:to store the y-coordinate of the first end point

Member functions/methods:

Plane(int nx,int ny):parameterized constructor to assign the data members x1=nx and y1=ny

void Show():to display the coordinates

Classname:Circle

Data members/instance variables:

x2:to store the x-coordinate of the second end point

y2:to store the y-coordinate of the second end point

radius:double variable to store the radius of the circle

area:double variable to store the area of the circle

Member functions / methods:

Circle(…):parameterized constructor to assign values to data members of both the classes

void findRadius():to calculate the length of radius using the formula:

(âˆš(x2-x1)2+(y2-y1)2 )/2

assuming that x1, x2, y1, y2 are the coordinates of the two ends of the diameter of a circle

void findArea():to find the area of circle using formula: Ï€r2.

The value of Ï€ is 22/7 or 3.14

void Show():to display both the coordinates along with the length of the radius and area of the circle

Specify the class Plane giving details of the constructor and void Show(). Using the concept of inheritance, specify the class Circle giving details of the constructor,void findRadius(),void findArea() and void Show().

The main function and algorithm need not be written.

# Share code with your friends

Share on whatsapp

Share on facebook

Share on twitter

Share on telegram

Code

` ````
```public class Plane
{
double xl,yl;
Plane(double nx,double ny)
{
xl=nx;
yl=ny;
}
void Show()
{
System.out.println("x-coordinate="+xl);
System.out.println("y-coordinate="+yl);
}
}
public class Circle extends Plane
{
double x2,y2,radius,area;
Circle(double nx,double ny,double a,double b)
{
super(nx,ny);
x2=a;
y2=b;
}
void findRadius()
{
radius=(Math.sqrt(Math.pow((x2-xl),2)+Math.pow((y2-yl),2)))/2;
}
void findArea()
{
area=3.14*radius*radius;
}
void Show()
{
super.Show();
System.out.println("Second x-coordinate="+x2);
System.out.println("Second y-coordinate="+y2);
System.out.println("Length of radius="+radius);
System.out.println("Area ="+area);
}
}