mohammedabdulbari/Java-SE

correct one

Closed this issue · 0 comments

import java.lang.*;
class Rectangle
{
private double length;
private double breadth;

public Rectangle()
{
    length=1;
    breadth=1;
}

public Rectangle(double l,double b)
{
    setLength(l);
    setBreadth(b);
}

public Rectangle(double s)
{
    length=breadth=s;
}

public void setLength(double l)
{
    if(l>0)
         length=l;
    else
         length=0;

}
public void setBreadth(double b)
{
    if(b>0)
         breadth=b;
    else
        breadth=0;
}

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

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

public double circumference()
{
    return perimeter();
}

public boolean isSquare()
{
    if(length==breadth)
        return true;
    else
        return false;
}

}
class DataHidingConstructors
{
public static void main(String argms[])
{
Rectangle r1=new Rectangle(-1,-2);

    System.out.println(r1.Area());
    System.out.println(r1.perimeter());
    System.out.println(r1.circumference());
    System.out.println(r1.isSquare());
}

}