calculate area of rectangle using parameterised constructor in java

Solutions on MaxInterview for calculate area of rectangle using parameterised constructor in java by the best coders in the world

showing results for - "calculate area of rectangle using parameterised constructor in java"
Sara
06 Aug 2018
1import java.io.BufferedReader;
2import java.io.IOException;
3import java.io.InputStreamReader;
4class RectangleShape 
5{
6   int area, length, breadth;
7   // Parameterized constructor
8   RectangleShape(int l, int b) 
9   { 
10      length = l; 
11      breadth = b; 
12   } 
13   void getArea() 
14   { 
15      area = length * breadth; 
16      System.out.println("Area of rectangle : " + area); 
17   } 
18}
19public class FindArea 
20{
21   public static void main(String[] args) throws IOException
22   {
23      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));        
24      int length, breadth; 
25      System.out.println("Please enter length : ");
26      String strLength = br.readLine(); 
27      length = Integer.parseInt(strLength);
28      System.out.println("Please enter breadth : ");
29      String strBreadth = br.readLine(); 
30      breadth = Integer.parseInt(strBreadth); 
31      RectangleShape rs = new RectangleShape(length, breadth); 
32      rs.getArea();
33   }
34}