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....

Recommended Answers

All 5 Replies

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

}

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
}

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.