Computer Science, asked by choudharyparvesh2001, 1 month ago

Write a program to print the area of a rectangle by creating a class named 'Area'
having two functions.
First function named as 'setDim' takes the length and breadth of the rectangle as
parameters and the second function
named as 'getArea' returns the area of the rectangle. Length and breadth of the
rectangle are entered through keyboard. In Java

Answers

Answered by dreamrob
12

Program:

import java.util.*;

public class Area

{

   double l , b;

   void setDim(double ll , double bb)

   {

       l = ll;

       b = bb;

   }

   double getArea()

   {

       return l*b;

   }

   public static void main(String args[])

   {

       Scanner Sc = new Scanner(System.in);

       double l , b;

       System.out.print("Enter Length : ");

       l = Sc.nextDouble();

       System.out.print("Enter Breadth : ");

       b = Sc.nextDouble();

       Area rect = new Area();

       rect.setDim(l , b);

       System.out.print("Area of Rectangle : " + rect.getArea());

   }

}

Output:

Enter Length : 10.5

Enter Breadth : 5.5

Area of Rectangle : 57.75

Similar questions