Develop a class named Rectangle with private data members length and width. Make a parameterized Constructor to initialize data members. Now make two methods rectarea() and rectperi() to calculate area and perimeter. Test the class Rectangle.
*/
importjava.util.*;
classRectangle
{
privatelonglength,area;
privatelongwidth,peri;
Rectangle(longl,longw)
{
length=l;
width=w;
}
publiclongArea(longa,longb)
{
area=a*b;
returnarea;
}
publiclongPerimeter(longa,longb)
{
peri=2*(a+b);
returnperi;
}
publicvoidDisplay()
{
System.out.println("Area : "+area);
System.out.print("Perimeter : "+peri);
}
}
classTask
{
publicstaticvoidmain(String... args)
{
longl1,w1;
Scannersc = newScanner(System.in);
System.out.print("Enter the length of rectangle=");
l1=sc.nextLong();
System.out.print("Enter the width of rectangle=");
w1=sc.nextLong();
Rectangled = newRectangle(l1,w1);
System.out.println("Area Of Rectangle="+d.Area(l1,w1));
System.out.println("Perimeter Of Rectangle="+d.Perimeter(l1,w1));