Question: Java I - create a Java program that will display a simple text menu with three options. The program will use if and else if
Java I - create a Java program that will display a simple text menu with three options. The program will use if and else if statements to determine which option was taken and then execute statements based on the selection made.
---------------
Specific Requirements
-
Display a menu of three numbered items as follows: 1. Area of a Rectangle, 2. Area of a Circle, 3. Area of a Triangle.
-
Put a well-worded prompt at the top of the menu telling the user what the program does, and prompt the user to enter a 1, 2, or a 3.
-
Use if, else if, and else statements to determine what selection the user made, and to make the proper calculation based on that selection.
-
The area of a rectangle is: rectangle length times the rectangle width.
-
The area of a circle is: Math.PI times (radius times radius). The radius times radius is just a simple way to square the radius. Also, PI is a constant in the Math class (much more on classes later in the course). Note that you can use the pow method (more on methods later in the course) of the Math class to square the radius: *Math.PI * Math.pow(radius, 2). radius is the length of the radius, and 2 is the power to which the number is raised (in this case squared). You may use either method to square the radius.
-
The area of a triangle is: the triangle base times the triangle height divided by 2.
-
Make the last else catch any number not within the range of 1-3, and display a message to the user that their selection was not within the range.
-
Declare the necessary variables. Use good descriptive names. Note that in these calculations, there is a possibility of a fractional part for an answer.
-
Assume that all dimensions are in feet.
-
Output the area of whatever shape was calculated, along with the two dimensions used. Put clear labels on all output describing what each number represents. You may choose the layout of the output.
-
Do not use break or resume in this program.
-
All indentations should be four spaces.
Example 1. Menu Format
Explanation of what the program does (Write something meaningful here). Prompt the user for input: (Make the request for input clear.) 1. Area of Rectangle 2. Area of a Circle 3. Area of a Triangle
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
