Answers for "Calculate area of rectangle using parameterised constructor in java"

1

Calculate area of rectangle using parameterised constructor in java

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();
   }
}
Posted by: Guest on February-09-2021

Code answers related to "Calculate area of rectangle using parameterised constructor in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language