public class Teacher { /* Field to store the numbers to enter and work with. Initially undefined. */ public static double numbers[]; /* Displays a menu of choices on the screen */ public static void showMenu() { System.out.println(); System.out.println(); System.out.println(" Cool Statistics Program"); System.out.println(" ***********************"); System.out.println(); System.out.println(" a - enter numbers"); System.out.println(" b - view numbers"); System.out.println(" c - edit numbers"); System.out.println(" s - show stats"); System.out.println(" h - help"); System.out.println(); System.out.println(" x - exit"); } /* Prompts user to enter a character and returns it in lower case */ public static char getChoice() { System.out.println(); System.out.print("Your choice: "); String s = Console.readString(); System.out.println(); System.out.println(); return s.toLowerCase().charAt(0); } /* Chooses different actions (methods) depending on the choice */ public static void actAccordingly(char choice) { if (choice == 'a') enterNumbers(); else if ((choice == 'b') && (numbers != null)) viewNumbers(); else if (choice == 's') showStats(); else if (choice != 'x') System.out.println("Invalid choice - DODO"); } /* Ask user how many numbers to enter, then prompts user to enter each one. Numbers are stored in the field ‘numbers’. If numbers already exist, they will be overridden by the new ones. */ public static void enterNumbers() { System.out.println("Entering numbers"); System.out.print("How many numbers: "); int N = Console.readInt(); numbers = new double[N]; for (int i = 0; i < N; i++) { System.out.print("Enter number: "); numbers[i] = Console.readDouble(); } } /* Display any numbers entered on the screen. The field ‘numbers’ must be defined prior to calling this method. */ public static void viewNumbers() { System.out.println("Viewing numbers"); } /* Asks which number to change, asks for a replacement to that number, then changes the corresponding value of the field ‘numbers’. The field ‘numbers’ must be defined prior to calling this method. */ public static void editNumbers() { System.out.println("Editing numbers"); } /* Displays various stats about the field ‘numbers’. As a minimum, show the count, min, max, sum, average, and standard deviation. The field ‘numbers’ must be defined prior to calling this method. */ public static void showStats() { System.out.println("Stats"); System.out.println("Minimum is: " + findMin()); } /* Computes the sum of values in the field ‘numbers’ and returns it. The field ‘numbers’ must be defined prior to calling this method. */ // public static double findSum() /* Computes the sum of the squares of the values in the field ‘numbers’ and returns it. The field ‘numbers’ must be defined prior to calling this method. */ // public static double findSumOfSquares() /* Finds the minimum value in ‘numbers’ and returns it. The field ‘numbers’ must be defined prior to calling this method. */ public static double findMin() { double smallest = numbers[0]; for (int i = 0; i < numbers.length; i++) { if (numbers[i] < smallest) smallest = numbers[i]; } return smallest; } /* Finds the maximum value in ‘numbers’ and returns it. The field ‘numbers’ must be defined prior to calling this method. */ // public static double findMax() /* Displays some brief help and ‘about’ info */ public static void showHelp() { } public static void main(String args[]) { char choice = ' '; while (choice != 'x') { // show menu showMenu(); // get user choice choice = getChoice(); // act according to choice actAccordingly(choice); } System.out.println("Thanks, come again."); } }