/* * Problem Set 1 * * A simple interactive program that performs operations * on a set of three integers. * * CS112 * */ import java.util.*; /* * Program Class Defintion */ public class SimpleStats { /* * printMenu() * * Method to display user options. */ public static void printMenu() { System.out.println("(0) Enter new numbers"); System.out.println("(1) Find the largest"); System.out.println("(2) Compute the sum"); System.out.println("(3) Compute the range (largest - smallest)"); System.out.println("(4) Compute the average"); System.out.println("(5) Print the numbers in ascending order"); System.out.println("(6) Quit"); System.out.println(); } /*** PUT YOUR SEPARATE HELPER METHODS FOR OPTIONS 1-5 HERE ***/ /* * main() * * Program execution begins with this method. */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); // variable declarations int n1 = 2; int n2 = 4; int n3 = 6; boolean more_input = true; /* * Control loop */ do { System.out.print("The current numbers are: "); System.out.println(n1 + " " + n2 + " " + n3); printMenu(); System.out.print("Enter your choice: "); int choice = scan.nextInt(); /* * Expand this conditional statement to process choices 1-5. * Make sure to follow the guidelines in the assignment for * doing so. */ if (choice == 0) { System.out.print("Enter three new numbers: "); n1 = scan.nextInt(); n2 = scan.nextInt(); n3 = scan.nextInt(); } else if (choice == 6) { more_input = false; } else { System.out.println("Invalid choice. Please try again."); } System.out.println(); } while (more_input); System.out.println("Have a nice day!"); } }