You are on page 1of 3

Q : A super class perimeter has been defined to calculate the perimeter of a parallelogram .

Define a subclass Area to compute the area of the parallelogram by using the required data
members of the super class.The detail are given below:

Class name : perimeter


Variables:
a : to store length in decimal
b :to store the breadth in decimal
Member Function:
perimeter(….) :parameterized constructor to assign values to data members
double calculate() :calculate and return the perimeter of a parallelogram as 2*(length+breadth)
void show() :to display the data members along with the perimeter of a parallelogram

Class name : Area


Variables :
h :to store the height in decimal
Area :to store the area of the parallelogram
Member function:
Area(…..) :parameterized constructto assign values to members of both the classes
Void doarea() :compute the area as (breadth*length)
Void show () : display the data members of both classes along with the area and perimeter of
the Parallelogram.
Specify the class perimeter giving details of the constructor all the member function of both the
classes

Algorithm:-
1.Start
2.A base class perimeter is created with given parameter of details.
3.All the parameters are initialized in the constructor.
4.the perimeter is calculated in calculate() and is displayed by the function show().
5.Another class named Area is created which inherits its properties from the base class
perimeter.
6.The derived class gets it’s variables initialized along with the variables of the super class.
7.The keyword super is used to call the constructor of the super class and passs values to the
respective variables.
8.The area of the parallelogram is calculated in void doarea() by the given formula.
9.Then the dimensions along with the perimeter and area is printed in void show() by the use of
super keyword
10. Another class is created to create main for ease of access.
11. Object of class Area is created in the main and the required functions are called.
12. Stop

Page | 1
Program:-
import java.util.*;
class perimeter
{
double a,b;
perimeter(double aa,double bb)
{ a=aa; b=bb;}
double calculate()
{ return (2*(a+b));
}
void show()
{System.out.println("\n Length="+a);
System.out.println("\n Breadth="+b);
System.out.println("\n perimeter="+ calculate());
}
}
class Area extends perimeter
{ double h; double area;
Area(double aa, double bb, double cc)
{ super(aa,bb);
h=cc;
}
void doarea()
{ area=h*b; }
Void show()
{ super.show();
System.out.println("\n Height= "+h);
System.out.println("\n Area= "+area);
}
}
public class execute
{ public static void main (String args[])
{Scanner sc=new Scanner (System.in);
System.out.println("Enter length");
double x=sc.nextDouble();
System.out.println("Enter breadth");
double y=sc.nextDouble();
System.out.println("Enter the height");
double z=sc.nextDouble();
Area ob =new Area(x,y,z);
ob.doarea();
ob.show();
} }

Page | 2
Output:-

Enter length
3
Enter breadth
7
Enter the height
9

Length=3.0

Breadth=7.0

perimeter=20.0

Height= 9.0

Area= 63.0

Variable description:-
Variable Type Description
a double to store length in decimal
b double to store the breadth in decimal
h double to store the height in decimal
area double to store the area of the parallelogram
sc Object variable To accept a variable from console
x double To store the length in main metod
y double To store the breadth in main metod
z double To store the height in main metod

Page | 3

You might also like