Thursday, March 1, 2012

Challenge 049’s Solution

To complete Challenge 49, the following codes must be placed into BlueJ™:
 
import java.lang.Math;
public class Circle extends Shape
{
    private double radius;
    public Circle(String name, double r)
    {
        super(name);
        radius = r;
    }
    public double area()
    {
        return (Math.PI * radius * radius);
    }
    public double perimeter()
    {
        return (2 * radius * Math.PI);
    }
}
 
public class Square extends Shape
{
    private double length;
    public Square(String name, double ℓ)
    {
        super(name);
        length = ℓ;
    }
    public double area()
    {
        return (length * length);   
    }
    public double perimeter()
    {
        return (length * 4);
    }
}
 
−Phoenix

1 comment:

  1. Outstanding. As a matter of convention, no special chars for variable names. 900 XPs awarded for completion.

    ReplyDelete