Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*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

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

Recommended Textbook for

Genomes And Databases On The Internet A Practical Guide To Functions And Applications

Authors: Paul Rangel

1st Edition

189848631X, 978-1898486312

Students also viewed these Databases questions

Question

EXPLAIN two strategies used to recruit non-permanent staff.

Answered: 1 week ago