Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java language Also, the user cannit provide negative amounts, and prints a warning message. Purpose: The purpose of this lab is to practice calculating a

image text in transcribed
Java language
Also, the user cannit provide negative amounts, and prints a warning message.
image text in transcribed
Purpose: The purpose of this lab is to practice calculating a running total (except using multiplication) and relying on a sentinel value to terminate a loop. Some consideration is also given to input validation as a bonus. Task: Name your project either MoreGeoMeans_FirstName_LastName or Lab5_FirstName_LastName. Remember to include a documentation comment summarizing the program For this program, you will need a few variables. You should have an object of the Scanner class to read user input. You will also need two double variables: one to hold the product of all user inputs provided up to the current one (be careful about what this variable is initialized to) as well as one to hold the count of the number of user inputs. You may also need two more double variables: one to hold each individual user input before multiplying it by the previous inputs and one to hold the final geometric mean result. You will then implement a loop to continuously accept user input until the user provides a sentinel value of 0 (since the final result would always be 0, it is not useful to include a 0 in the inputs). If the user provides valid input, multiply this with the product of all previous inputs and increment the count for user inputs. After the user is done providing inputs and uses the sentinel value of 0, refer to the following equation to complete the calculations for the geometric mean: Nxj X2 X3... Xn The sequence of products is the total you got while collecting user inputs. Keep in mind that getting the nth-root of a number is equivalent to raising that number to the power of 1. After calculating the geometric mean, print the result to the console formatted to two decimal places. Here are two sample sequences of user inputs and program outputs. The first considers no bonus while the second demonstrates the expectations for the bonus. In either case, assume the user provides at least one valid input before entering the sentinel value. Please enter a number: 8 Please enter a number: 12 Please enter a number: @ The geometric mean of the numbers provided is 9.80. Please enter a number: 10 Please enter a number: -1 Negative measurements cannot be used Please enter a number: 15 Please enter a number: @ The geometric mean of the numbers provided is 12.25

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

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions