/* Problem Statement This class will calculate and display the average of sets of numbers entered by the user. It will calculate the mean average of that set and display it, repeatedly, until the user says that he has no more sets. This program will then display the number of sets processed and the mean average of all the values in all the sets. */ import java.util.Scanner; public class CalculateAverages { public static void main(String[] args) { // Declare variables double count; // Number of values left to be entered in the current set double unalteredCount; // Total number of values in the current set double value; // An element of the current set double setTotal = 0; // Running total of the values in the current set double setAverage; // Mean average of the values in the current set double setCount = 0; // Total number of sets entered double grandTotal = 0; // Total of all values entered double grandCount = 0; // Total number of values entered double totalAverage; // Mean average of all values entered // For determining if there's another set to be entered or not String another; // To scan in the count of elements in the current set Scanner scanCount = new Scanner (System.in); // To scan in the elements in the current set Scanner scanValues = new Scanner (System.in); // Ask user if there is a set to be entered Scanner scanSets = new Scanner (System.in); System.out.print("Is there a set to be entered (y/n)? "); another = scanSets.nextLine(); while (another.equalsIgnoreCase("y")) // Allows y or Y { // Ask user how many values are in the set. System.out.print("How many values are in this set? "); count = scanCount.nextDouble(); unalteredCount = count; // preserves number in set for figuring average grandCount = count + grandCount; // to figure totalAverage // Ask user for values of the set. while (count > 0) { System.out.print("Enter a value: "); value = scanValues.nextDouble(); setTotal = value + setTotal; count = count - 1; // counts down number of elements left to be entered } // Calculate and display mean average of set. setAverage = setTotal / unalteredCount; System.out.println("Average of set(s) entered: " + setAverage); grandTotal = setTotal + grandTotal; // Count number of sets entered. setCount = setCount + 1; // Ask user if there is another set to be entered. System.out.println(); System.out.print("Is there another set to be entered (y/n)? "); another = scanSets.nextLine(); setTotal = 0; } // When no more sets are to be entered, calculate mean average of all sets // and display total number of sets. System.out.println("Total number of sets is: " + setCount); totalAverage = grandTotal / grandCount; System.out.println("Average of all sets is: " + totalAverage); } }