Question: Java exercise a) Write a method getAverage that takes a single integer as a parameter and returns a double value. The method should use showInputDialog
Java exercise
a) Write a method getAverage that takes a single integer as a parameter and returns a double value. The method should use showInputDialog to prompt the user for a number of double values and then return their average. Your method should use the integer parameter as the number of prompts that are needed (and so also the number of values that need to be collected).
b) Write a main method that prints to output a prompt for the user. Use the Scanner class to read in a single integer value that will represent the number of values that will be provided to average. Then, use this value in a call to the method from part (a). Use the returned value from this method to print to output a nicely formatted message that gives both the average value, and also indicates the number of values that were collected.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
