import java.io.*; class Rectangle { int length; int width; BufferedReader br;
public void readAttributes() throws IOException //reading length and width { System.out.println("Enter the dimensions of the rectangle."); br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the length:"); length=Integer.parseInt(br.readLine()); System.out.print("Enter the width:"); width=Integer.parseInt(br.readLine()); } public void getArea() //calculating area { System.out.println("Area of rectangle is: "+ (length*width)); } public void getPerimeter() //calculating perimeter { System.out.println("Perimeter of rectangle is: "+ 2*(length+width)); } public static void main(String args[]) throws IOException //main method { Rectangle r=new Rectangle(); //object for the class r.readAttributes(); //calling three methods r.getArea(); r.getPerimeter(); } }
OUTPUT:
Enter the dimensions of the rectangle. Enter the length:10 Enter the width:20 Area of rectangle is: 200 Perimeter of rectangle is: 60