/* 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. (first we will write a method that adds 2 numbers and returns their sum). */ import java.util.Scanner; public class AverageMethod2 { /* main will call and methods and print msgs */ public static void main(String[] args) { // test sum2nums // int sum = sum2nums(34, 21); can assign the return value System.out.println("in main, sum is: " + sum2nums(34,21)); // example of composition System.out.println("second sum: " + sum2nums(sum2nums(10, 20), 30)); 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); System.out.println("average is: " + average); // could have done all 3 stmts in one stmt as follows System.out.println("average is: " + average(numElts, sum(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