Sunday 27 March 2016

Demo to calculate area of rectangle

Area of Rectangle


class Rectangle {
  double length;
  double breadth;

        public Rectangle () {
    length= 0 ;
    breadth = 0;  
  }
  public Rectangle(double l,double b) {
  
    length = l;
    breadth = b;
    
  }
  
  public void setLength(double l) {

    length = l;

  }
  public void setBreadth(double b) {

    breadth = b;

  }
  public double getLength () {
    return length;  

  }
  public double getBreadth () {
    return breadth;  

  }
  public double Area() {
    return (length * breadth);  
  }
  public double Perimeter() {
    return (2*(length+breadth));  
  }
}

public class RectangleDemo {
  public static void main(String[] args){
    Rectangle rect = new Rectangle(10,20);
    double area = rect.Area();
    double l = rect.getLength();
    double b = rect.getBreadth();
    double temp = l*b;
    System.out.println(area);
    System.out.println(temp);

  

  
  }





}






No comments:

Post a Comment