Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Having trouble with getting the main set up. Very stuck. This assignment will acquaint you with the use of parameter passing, return values, if/else blocks,

image text in transcribed

image text in transcribed

image text in transcribed

Having trouble with getting the main set up. Very stuck.

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 areas of both shapes and print a summary statement comparing the two shapes. Write a complete class called AreaComparison that has the following: . (4 points) getShape Type method: that prompts the user for the type of the shape and returns the lower case version of the shape type ("rectangle", "triangle" or "circle"). (4 points) promptAnd CalculateRectangleArea method: prompts the user for the dimensions of the rectangle (width and height), calculates, reports it to console and returns the area of the rectangle. (4 points) promptAnd Calculate TriangleArea method: prompts the user for the dimensions of the triangle (base and height), calculates, reports it to console and returns the area of the triangle. (4 points) promptAnd Calculate Circle Area method: prompts the user for the dimensions of the circle (radius), calculates, reports it to console and returns the area of the circle. (4 points) promptAndcalculate Area method: takes shape type as input parameter and calls one of the three promptAndCalculate* methods above depending on the shape type. If the shape type is not one of the known ones (rectangle, triangle or circle), this method should throw an illegalArgumentException. (6 points) main method: o Declares and initializes a Scanner object to be used throughout to read user input. o Calls methods getShape Type and promptAndcalculateArea methods successively to get the shape type and area for two shapes. o Compares these two values and prints the final report. When printing the areas, 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. O' TOPPO will it need to perform the task, and accordingly decide the method signature for each. To be able to use the Scanner object effectively you will have to pass it to all the methods that prompt the user for input. The basic equation to calculate the area of a rectangle is (Width x Height) The basic equation to calculate the area of a triangle is 2 x ( Base x Height) The basic equation to calculate the area of a circle is (pi) x ( Radius ) x ( Radius ) You can use Math.pl for the value of Pi When comparing strings, use the equals method to compare the values of the strings. When printing the areas, 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 (rectangle, triangle, or circle): rectangle Specify rectangle width: 200 Specify rectangle height: 200 The area of the rectangle is (40000.000) square units. Please choose your shape (rectangle, triangle, or circle): circle Specify circle radius: 200 The area of the circle is (125663.706) square units. The area of the rectangle (40000.000 square units) is less than the area of the circle (125663.706 square units). Sample run 2 (text in orange is what user has entered as input): Please choose your shape (rectangle, triangle, or circle): circle Specify circle radius: 150 The area of the circle is (70685.835) square units. Please choose your shape (rectangle, triangle, or circle): triangle Specify triangle base: 250 Specify triangle height: 150 The area of the triangle is (18750.000 square units. The area of the circle (70685.835 square units) is greater than the area of the triangle (18750.000 square units. Sample run 3 (text in orange is what user has entered as input): Please choose your shape (rectangle, triangle, or circle): rectangle Specify rectangle width: 300 Specify rectangle height: 200 The area of the rectangle is (60000.000) square units. Please choose your shape (rectangle, triangle, or circle): triangle Specify triangle base: 400 Specify triangle height: 300 The area of the triangle is (60000.000) square units. The area of the rectangle (60000.000 square units) is equal to the area of the triangle (60000.000 square units). Sample run 4 (text in orange is what user has entered as input): Please choose your shape (rectangle, triangle, or circle): pentagon Exception in thread "main" java.lang.IllegalArgumentException: Unknown shape at AreaComparison.promptAndcalculateArea (Area Comparison.java:51) at Area Comparison.main (Area Comparison.java:15)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Students also viewed these Databases questions