You are on page 1of 5

public interface Shape {

public double getArea();


}
public class Rectangle implements Shape {

double length;
double bredth;
public Rectangle(double length, double bredth) {
super();
this.length = length;
this.bredth = bredth;
}
@Override
public double getArea() {

return length*bredth;
}
@Override
public String toString() {
return "Rectangle [length=" + length + ", bredth="
+ bredth + "Area : "+getArea()+" ]";
}

}
public class Circle implements Shape
{
double radius;
public Circle(double radius) {
super();
this.radius = radius;
}
@Override
public double getArea() {

return 3.143*radius*radius;
}
@Override
public String toString()
{
return "Circle [radius=" + radius + "Area: "+getArea()+"
]";
}

}
public class Square implements Shape {

double side;

public Square(double side) {


this.side=side;
}

@Override
public double getArea() {
return side*side;
}
@Override
public String toString()
{
return "Square [side=" + side + "Area:
"+getArea()+" ]";
}

}
import java.util.ArrayList;
import java.util.List;
public class MainShape {
static Shape getBiggestAreaShape(List<Shape> shapes)
{
Shape sh=shapes.get(0);
for (int i = 1; i <shapes.size(); i++) {

Shape temp=shapes.get(i);
if(sh.getArea()<temp.getArea())
sh=temp;
}

return sh;
}
public static void main(String[] args) {
List<Shape> shapes=new ArrayList<Shape>();
shapes.add(new Circle(3.6));
shapes.add(new Circle(4.3));
shapes.add(new Square(6.7));
shapes.add(new Rectangle(8.9,9.7));
shapes.add(new Square(3.4));

Shape bs=getBiggestAreaShape(shapes);
System.out.println("Biggest area shape is: "+bs);
}

You might also like