0

Trying to learn Java on my own with the book "Starting out with java" The question is this

Write a class that has three overloaded static methods for calculating the areas of the following geometric shapes:

circles

rectangles

cylinders

(it gives the formulas for the are of them)

Because the three methods are to be overloaded, they should each have the same name, but different parameter lists. Demonstrate the class in a complete program.

My answer is this:

```
public class Area
{
static double Area (double rad)
{
return Math.PI* (rad * rad);
}
static int Area (int wid, int len)
{
return wid * len;
}
static double Area (double rad, double heig)
{
return Math.PI * (rad * rad) * heig;
}
}
```

```
public class Main
{
/**
* @param args
*/
public static void main(String[] args)
{
double radiusCircle = 3;
int lengthRectangle = 10;
int widthRectangle = 15;
int heightCylinder = 20;
double raidusCylinder = 4;
System.out.println ("The area of a circle with radius " + radiusCircle +
" is " + Area.Area(radiusCircle));
System.out.println ("The area of a rectangle with a lenght of " +
lengthRectangle + " and a width of " + widthRectangle +
" is " + Area.Area(widthRectangle, lengthRectangle));
System.out.println ("The area of a cylinder with a radius " + raidusCylinder +
" and a height of " + heightCylinder + " is " +
Area.Area(raidusCylinder, heightCylinder));
}
}
```

It works, but i'm not sure that it fits the way it should? How does it look?

Thanks