import javax.swing.JOptionPane; /** * A class to give students practice using "cascaded" ifs to implement * multiple-alternative decisions * * @author Greg */ public class DecisionTester2 { public static void main(String[] args) { // Exercise 1: The following code reads an int. Use "cascaded if" // statements to print the number along with a message indicating // whether it is positive, negative, or zero String input = JOptionPane.showInputDialog("Enter an int") ; int number = Integer.parseInt(input) ; // insert cascaded if statements here JOptionPane.showMessageDialog(null,"press OK to continue") ; // Exercise 2: A supermarket awards coupons depending on how much a // customer spends. E.g. if you spend $50 you will get a coupon worth // $4 (8% of that amount). Use cascaded if statements to compute // the value of the coupon earned, based on the table below. Note // that the value of the coupon is the indicated percentage // of the amount spent, and not just the percentage amount itself. // // Amount Spent Coupon Percentage // ============ ================= // less than $10 no coupon // from $10 to $75 8% // more than $75 to $210 11% // over $210 14% // // sample output: // Your purchase of $100.00 earns a discount coupon of $11.00 input = JOptionPane.showInputDialog("Enter cost of groceries") ; double amount = Double.parseDouble(input) ; double couponValue = 0.0 ; // insert cascaded if statements here to compute coupon value System.out.printf("%nYour purchase of $%.2f earns a discount coupon " + "of $%.2f%n", amount, couponValue); System.exit(0); } }