/* 10/16/2019
 * Review Lab 10: Void Methods
Write a program with 2 methods: main, average
Method average will accept an integer parameter numElts, 
which represents the number of data elements to be read in.
The method should read in (from the keyboard) numElts
numbers, and print their average.
*/
import java.util.Scanner;

public class AverageMethod {
  /* 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();
    average(numElts, sc); // method call
    int y=10;
    increment(y);
    System.out.println("in main, y="+y);
  }
     
  /** average takes the average of a set of numbers
    * @param num the number of elements to read in
    */
  public static void average(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;
    }
    // fall out of loop, print average
    System.out.println("Average is: " + sum/num);
  }
  /** although x is incremented in the method, this does
    * NOT affect the variable passed in. */
  public static void increment(int x) {
    x++;
    System.out.println("in method increment, x="+x);
  }
}
    
    
    
    