/* Java Input Output Example */ import java.util.Scanner; public class Main { public static void main(String[] args) { // using the utilites to read input into variables int puppies = promptInt("how many puppies?"); String name = promptString("what name?"); double dollars = promptDouble("how many dollars?"); boolean isGood = promptBoolean("was it good?"); // show the results System.out.println("You said " + puppies + " puppies"); System.out.println("You said " + name + " was the name"); System.out.println("You said " + dollars + " dollars"); System.out.println("You said it was " + isGood + " that it was good"); } /* Simple Utility methods that prompt the user and return input If you enter the wrong type of input, the program will end with an error! */ // utility for reading in integer input public static int promptInt(String promptText) { System.out.print(promptText + " "); Scanner scan = new Scanner(System.in); int response = scan.nextInt(); return response; } // utility for reading in double input public static double promptDouble(String promptText) { System.out.print(promptText + " "); Scanner scan = new Scanner(System.in); double response = scan.nextDouble(); return response; } // utility for reading in String input public static String promptString(String promptText) { System.out.print(promptText + " "); Scanner scan = new Scanner(System.in); String response = scan.nextLine(); return response; } // utility for reading in boolean input public static boolean promptBoolean(String promptText) { System.out.print(promptText + " (y/n) "); Scanner scan = new Scanner(System.in); String response = scan.nextLine(); return response.equalsIgnoreCase("y"); } }