Question: *DO NOT* use your name in your code 1. Include comments If you use a package in your code or you use an Eclipse project,

*DO NOT* use your name in your code 1. Include comments

If you use a package in your code or you use an Eclipse project, it must be named copGeometryHomework. Your class name must match your .java file name

Write a Java program that does the following:

(1) Program shall prompt the user to enter an integer number as follows, and read the number entered by the user into variable choice: Please enter either 1 or 2:

(2) If choice is 1, the program shall print the area of a triangle: Area = (b h) / 2.

The program shall first prompt the user to enter the values for variables b and h as follows:

Please enter two non-negative integers for base and height:

(a) If numbers entered for b and h are non-negative, the following output shall be displayed on the screen:

Area of a triangle with base=, height=: .

The area shall be computed using a method named calcTriangleArea: takes two integers as arguments, and returns the value of the computed area as a double.

(b) If either number entered for b or h is negative, the program shall exit without any message

(3) If choice is 2, the program shall print the area of a circle: Area = pi r^2 .

The program shall first prompt the user to enter the value for variable r as follows:

Please enter a non-negative number for radius:

(a) If number entered for r is non-negative, the following output shall be displayed on the screen:

Area of a circle with radius=: .

The area shall be computed using a method named calcCircleArea: takes a double as argument, and returns the value of the computed area as a double. Note: you may use the Math.PI for your calculation.

(b) If the number entered for r is negative, the program shall exit without any message.

(4) If choice is neither 1 nor 2, the program shall display the following message and finish (exit): Please rerun the program entering either 1 or 2.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!