Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

First, write five methods that compute and return the following: 1.Area of a circle. This method takes one parameter, the radius. public static double

  

First, write five methods that compute and return the following: 1.Area of a circle. This method takes one parameter, the radius. public static double areaCircle (int radius) 2.Area of a rectangle. This method takes two parameters, the length and width public static int areaRectangle (int length, int width) 3.Area of a square. This method takes one parameter, the length of a side. public static int areaSquare (int side) However, because a square is just a special type of rectangle (where the sides have the same length), have this function call your area of a rectangle function to compute the answer. In other words, do not directly compute the area of a square inside this function, instead, call your area of a rectangle function with appropriate arguments and return the value that comes back. 4.The surface area of a rectangular prism. This method takes three parameters, the length, width, and height. public static int areaPrism (int length, int width, int height) This method takes three parameters, the length, width, and height. 5. The area of a ring, meaning a circle with an interior circle missing, like this. This function takes two parameters, the inner radius and the outer radius. public static double areaRing (int radouter, int radInner) Your area of a ring function should call your area of a circle method twice. Second, write your main method to do this: The user is first asked what kind of shape they want to calculate the area (or surface area) of. The user will type in the name of the shape as a string (e.g., circle, rectangle, square, prism, or ring). Use if-else statements to figure out what shape they wanted, then ask the user to type in the appropriate attributes of the shape (e.g., for circle you would ask for the area, for square you would ask for the length of a side). If the user types in an invalid shape name, then print an appropriate error message. Display the area of the shape, followed by a message asking the user if they want to calculate the area of another shape. If they answer yes, then run the program again. You should use a while loop for this part. Lastly Test your program Sample output that I made with my program: What shape do you want? square What is the side length? 7 The area of the square is 49 Do you want to calculate another area? yes What shape do you want? rectangle What is the length? 8 What is the width? 5 The area of the rectangle is 40 Do you want to calculate another area? yes What shape do you want? prism What is the length? 6 What is the width? 5 What is the height? 4 The surface area of the prism is 148 Do you want to calculate another area? yes What shape do you want? Hexagon I don't know that shape. Do you want to calculate another area? yes What shape do you want? square What is the side length? 5 The area of the square is 25 Do you want to calculate another area? yes What shape do you want? Ring What is the outer radius? 6 What is the inner radius? 4 The area of the ring is 62.83185307179586 What shape do you want? Circle What is the radius? 6 The area of the circle is 113.03999999999999 Do you want to calculate another area? no

Step by Step Solution

3.42 Rating (161 Votes )

There are 3 Steps involved in it

Step: 1

import javautil class area public static int decideString shap... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Java Programs A Back To Basics Approach

Authors: Stuart Reges, Marty Stepp

5th Edition

013547194X, 978-0135471944

More Books

Students also viewed these Marketing questions

Question

What is the area of a circle of radius (a) 11.37 m (b) 6.8 m?

Answered: 1 week ago