package CIS115; import java.util.Scanner; public class ForDoWhile { public static void main(String[] args) { // String password = "*****"; String user; do { user = promptString("password?"); } while (!user.equals(password)); // note semicolon for java syntax System.out.println("welcome user!"); // do while always uses same prompt double income; do { income = promptDouble("income?"); } while (income < 0); System.out.println("correct income: $" + income); // first prompt polite income = promptDouble("What is your income?"); while (income < 0) { // later, scold user System.out.println("No negative income!"); income = promptDouble("Try again! Income?"); } // count to 10 for (int count = 0; count < 10; count = count + 1) { System.out.println("#" + count); } // read a coupon, repeat if there are more double bill = 59.99; boolean more; do { double coupon = promptDouble("how much is your coupon?"); bill = bill - coupon; more = promptBoolean("Do you have more?"); } while (more); System.out.println("Your bill is now $" + bill); // count down System.out.println("Countdown:"); for (int count = 10; count > 10; count = count - 1) { System.out.println("#" + count); } // sum 25 to 75 int sum = 0; for (int i = 25; i <= 75; i = i + 1) { sum = sum + i; } System.out.println("total sum is " + sum); } /* 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 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"); } }