Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

This assignment will acquaint you with the use of parameter passing, return values, if/else blocks, and user input. You will create a program that prompts

image text in transcribed image text in transcribed image text in transcribed

This assignment will acquaint you with the use of parameter passing, return values, if/else blocks, and user input. You will create a program that prompts the user for a set of information, then executes simple algebra on that information and returns a summary report. Specifically, your program will ask the user to specify two simple geometric shapes along with their dimensions. The program will then calculate and report the volumes of both shapes and print a summary statement comparing the two shapes. Write a complete class called VolumeComparison that has the following: - (4 points) getShapeType method: that prompts the user for the type of the shape and returns the lower case version of the shape type ("box", "cone n or "sphere"). - (4 points) promptCalculatePrintBoxVolume method: prompts the user for the dimensions of the box (width, depth and height), calculates, reports it to console and returns the volume of the box. - (4 points) promptCalculatePrintConeVolume method: prompts the user for the dimensions of the cone (radius and height), calculates, reports it to console and returns the volume of the cone. - (4 points) promptCalculatePrintSphereVolume method: prompts the user for the dimensions of the sphere (radius), calculates, reports it to console and returns the volume of the sphere. - (4 points) promptCalculateVolume method: takes shape type as input parameter and calls one of the three promptCalculatePrint methods above depending on the shape type and returns the volume reported by that method. If the shape type is not one of the known ones (box, cone or sphere), this method should throw an IllegalArgumentException. - (6 points) main method: - Declares and initializes a Scanner object to be used throughout to read user input. - Calls methods getShapeType and promptAndCalculateVolume methods successively to get the shape type and volume for two shapes. - Compares these two values and prints the final report. When printing the volumes, make sure the numbers are printed rounded to 3 decimal places. - (4 points) - Include appropriate program documentation and formatting including: Your first and last name, the date of submission, code comments necessary to explain the operation of your program, and proper indentation of the code, etc. Tips: - For each of the methods, think about the following: What is the return type, what parameter(s) will it need to perform the task, and accordingly decide the method signature for each. - To be able to use the single Scanner object effectively you will have to pass it to all the methods that prompt the user for input. - You can look up the formulae for the volume of different shapes online. - You can use Math.PI for the value of Pi - When comparing strings, use the equals method to compare the values of the strings. - When printing the volumes, make sure the numbers are printed rounded to 3 decimal places. Sample run 1 (text in orange is what user has entered as input): Please choose your shape (box, cone, or sphere): box Specify box width: 35 Specify box depth: 25 Specify box height: 22.5 The volume of the box is (19687.500) cube units. Please choose your shape (box, cone, or sphere): sphere Specify sphere radius: 35 The volume of the sphere is (179594.380) cube units. The volume of the box (19687.500 cube units) is less than the volume of the sphere (179594.380 cube units) Sample run 2 (text in orange is what user has entered as input): Please choose your shape (box, cone, or sphere): sphere Specify sphere radius: 15 The volume of the sphere is (14137.167) cube units. Please choose your shape (box, cone, or sphere): cone Specify cone base: 25 Specify cone height: 15 The volume of the cone is (9817.477) cube units. The volume of the sphere (14137.167 cube units) is greater than the volume of the cone (9817.477 cube units). Sample run 3 (text in orange is what user has entered as input): Please choose your shape (box, cone, or sphere): box Specify box width: 22 Specify box depth: 10 Specify box height: 24 The volume of the box is (5280.000) cube units. Please choose your shape (box, cone, or sphere): box Specify box width: 12 Specify box depth: 44 Specify box height: 10 The volume of the box is (5280.000) cube units. The volume of the box (5280.000 cube units) is equal to the volume of the box (5280.000 cube units). Sample run 4 (text in orange is what user has entered as input): Please choose your shape (box, cone, or sphere): pyramid Exception in thread "main" java.lang. IllegalArgumentException: Unknown shape at VolumeComparison. promptAndcalculateVolume (VolumeComparison.java: 49) at VolumeComparison.main (VolumeComparison.java: 15) This assignment will acquaint you with the use of parameter passing, return values, if/else blocks, and user input. You will create a program that prompts the user for a set of information, then executes simple algebra on that information and returns a summary report. Specifically, your program will ask the user to specify two simple geometric shapes along with their dimensions. The program will then calculate and report the volumes of both shapes and print a summary statement comparing the two shapes. Write a complete class called VolumeComparison that has the following: - (4 points) getShapeType method: that prompts the user for the type of the shape and returns the lower case version of the shape type ("box", "cone n or "sphere"). - (4 points) promptCalculatePrintBoxVolume method: prompts the user for the dimensions of the box (width, depth and height), calculates, reports it to console and returns the volume of the box. - (4 points) promptCalculatePrintConeVolume method: prompts the user for the dimensions of the cone (radius and height), calculates, reports it to console and returns the volume of the cone. - (4 points) promptCalculatePrintSphereVolume method: prompts the user for the dimensions of the sphere (radius), calculates, reports it to console and returns the volume of the sphere. - (4 points) promptCalculateVolume method: takes shape type as input parameter and calls one of the three promptCalculatePrint methods above depending on the shape type and returns the volume reported by that method. If the shape type is not one of the known ones (box, cone or sphere), this method should throw an IllegalArgumentException. - (6 points) main method: - Declares and initializes a Scanner object to be used throughout to read user input. - Calls methods getShapeType and promptAndCalculateVolume methods successively to get the shape type and volume for two shapes. - Compares these two values and prints the final report. When printing the volumes, make sure the numbers are printed rounded to 3 decimal places. - (4 points) - Include appropriate program documentation and formatting including: Your first and last name, the date of submission, code comments necessary to explain the operation of your program, and proper indentation of the code, etc. Tips: - For each of the methods, think about the following: What is the return type, what parameter(s) will it need to perform the task, and accordingly decide the method signature for each. - To be able to use the single Scanner object effectively you will have to pass it to all the methods that prompt the user for input. - You can look up the formulae for the volume of different shapes online. - You can use Math.PI for the value of Pi - When comparing strings, use the equals method to compare the values of the strings. - When printing the volumes, make sure the numbers are printed rounded to 3 decimal places. Sample run 1 (text in orange is what user has entered as input): Please choose your shape (box, cone, or sphere): box Specify box width: 35 Specify box depth: 25 Specify box height: 22.5 The volume of the box is (19687.500) cube units. Please choose your shape (box, cone, or sphere): sphere Specify sphere radius: 35 The volume of the sphere is (179594.380) cube units. The volume of the box (19687.500 cube units) is less than the volume of the sphere (179594.380 cube units) Sample run 2 (text in orange is what user has entered as input): Please choose your shape (box, cone, or sphere): sphere Specify sphere radius: 15 The volume of the sphere is (14137.167) cube units. Please choose your shape (box, cone, or sphere): cone Specify cone base: 25 Specify cone height: 15 The volume of the cone is (9817.477) cube units. The volume of the sphere (14137.167 cube units) is greater than the volume of the cone (9817.477 cube units). Sample run 3 (text in orange is what user has entered as input): Please choose your shape (box, cone, or sphere): box Specify box width: 22 Specify box depth: 10 Specify box height: 24 The volume of the box is (5280.000) cube units. Please choose your shape (box, cone, or sphere): box Specify box width: 12 Specify box depth: 44 Specify box height: 10 The volume of the box is (5280.000) cube units. The volume of the box (5280.000 cube units) is equal to the volume of the box (5280.000 cube units). Sample run 4 (text in orange is what user has entered as input): Please choose your shape (box, cone, or sphere): pyramid Exception in thread "main" java.lang. IllegalArgumentException: Unknown shape at VolumeComparison. promptAndcalculateVolume (VolumeComparison.java: 49) at VolumeComparison.main (VolumeComparison.java: 15)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions