Computer Science, asked by tinavij99, 10 months ago

write a program in java to calculate area of rectangle using parameterized constructor with output​

Answers

Answered by reet2945
3

Pls mark as BRAINLIEST

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

class RectangleShape  

{

  int area, length, breadth;

  // Parameterized constructor

  RectangleShape(int l, int b)  

  {  

     length = l;  

     breadth = b;  

  }  

  void getArea()  

  {  

     area = length * breadth;  

     System.out.println("Area of rectangle : " + area);  

  }  

}

public class FindArea  

{

  public static void main(String[] args) throws IOException

  {

     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));        

     int length, breadth;  

     System.out.println("Please enter length : ");

     String strLength = br.readLine();  

     length = Integer.parseInt(strLength);

     System.out.println("Please enter breadth : ");

     String strBreadth = br.readLine();  

     breadth = Integer.parseInt(strBreadth);  

     RectangleShape rs = new RectangleShape(length, breadth);  

     rs.getArea();

  }

}

Answered by disha97969
0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class RectangleShape
{
int area, length, breadth;
// Parameterized constructor
RectangleShape(int l, int b)
{
length = l;
breadth = b;
}
void getArea()
{
area = length * breadth;
System.out.println("Area of rectangle : " + area);
}
}
public class FindArea
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int length, breadth;
System.out.println("Please enter length : ");
String strLength = br.readLine();
length = Integer.parseInt(strLength);
System.out.println("Please enter breadth : ");
String strBreadth = br.readLine();
breadth = Integer.parseInt(strBreadth);
RectangleShape rs = new RectangleShape(length, breadth);
rs.getArea();
}
}


Output:

Please enter length : 50
Please enter breadth : 20
Area of rectangle : 1000


Plz mark as BRAINLIEST
Similar questions