1…Area of a Circle ----(3.14 * (r*2))
2.Area of a Trapezoid ---- (height * (base1+base2) / 2)
3.Volume of a Sphere ---- (.75 * 3.14 *(radius*2))
4.Volume of a Cylinder ---- (3.14 * (radius * 2) + height

how would i make this using methods and switch statemnts.....

i've done it in if and else and i cant do it in the above said topic :c

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by tong1

You mean such as creating a method and returning a calculated radius?

your method signature/skeleton would look like this

``````//comments here
public int getArea(){

//calculations for the area of a circle goes here
//then return it's value

}``````

Edited by yasuodancez: n/a

Or, if you want to allow for multiple circles, triangles, or whatnot, you might allow for the input of a parameter or two, to represent the dimensions of the geometrical object in question. For a circle, for example, you need an int or a double, depending on whether you're dealing in integers or decimals.

Your return type will probably not be an int, if you're dealing in circles - unless you want to truncate the area down to an integer value. (You don't want a unit circle with radius 3 - unless you're in Kansas, where it's the law!)

i forgot you would have to input for the option example.
i would input 1 and it will print:
Area of a Circle

Or, if you want to allow for multiple circles, triangles, or whatnot, you might allow for the input of a parameter or two, to represent the dimensions of the geometrical object in question. For a circle, for example, you need an int or a double, depending on whether you're dealing in integers or decimals.

Your return type will probably not be an int, if you're dealing in circles - unless you want to truncate the area down to an integer value. (You don't want a unit circle with radius 3 - unless you're in Kansas, where it's the law!)

Good point.
So your code would look similiar to this...

``````//comments here

//calculations for the area of a circle goes here
//then return it's value
}``````

Edited by yasuodancez: n/a

Should we modify the formula ?