selection menu :
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

help pleaseee....

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 6 Years Ago 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
Result is:(answer)

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
public double getArea(double radius){

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

Edited 6 Years Ago by yasuodancez: n/a

Should we modify the formula ?

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

Edited 6 Years Ago by tong1: n/a

This article has been dead for over six months. Start a new discussion instead.