/* 10/16/2019 Value Methods Redo of Lab10 to use methods that return a value Use a 2 step solution. First method calculates sum of numbers read in, second method calculates average. Version 3 has the average method calling the sum method. */ import java.util.Scanner; public class AverageMethod3 { /* main will call and methods and print msgs */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("How many elements will be processed? "); int numElts = sc.nextInt(); // print average // first call the sum method // I am going to save the return value from sum method // and use it as the parameter to the call to average //double sum = sum(numElts, sc); //double average = average(numElts, sum); // NOTICE THAT MAIN DOES NOT USE SUM // SO IN THIS VERSION WE LET THE AVERAGE METHOD CALL SUM System.out.println("average is: " + average(numElts, sc)); } /** sum reads in a set of numbers and return their sum * @param num the number of elements to read in * @param keyboard is the Scanner object * @return sum of all numbers read in */ public static double sum(int num, Scanner keyboard) { double sum=0.0; for (int i=0; i