/* 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<num; i++) {
      System.out.println("Enter number: ");
      double nextNumber=keyboard.nextDouble();
      sum+=nextNumber;
    }
    return sum;
  }
  /** average accepts number of elements and calculates 
    * average of that number of elements by calling
    * sum to read in and sum the numbers.
    * @param num is the number of elements
    * @keyboard is the Scanner object necessary to pass to
    * sum method.
    * @return average of all numbers read in 
    */
  public static double average(int num, Scanner keyboard) {
    // call the sum method
    double sum = sum(num, keyboard);
    //return avg;
    return sum/num;
  }
 }
/* Lab 11:
 * Write a method that accepts a paramter of type double
 * representing a degrees Celcius. The method should
 * convert the degrees into Faranheit and return the value.
 * 
 * In main, you read in the degrees Celcius,
 * call the method,
 * and print the degrees Faranheit.
 * HINT: the method should not print or read anything.
 */
    
    
    
    