/* Lesley Hogan * July 17th 2003 * IfStatements.java * If-Else statements... More practice * Homework from: * http://chortle.ccsu.edu/cs151/Notes/chap12/progExercises12.html */ package net.bunnie.dos; import java.text.DecimalFormat; import net.bunnie.*; public class IfStatements { public static void main (String[] args) { KeyboardReader r = new KeyboardReader(); DecimalFormat dec = new DecimalFormat("$0.00"); int switchInt = 0; boolean loop = true; do { switch (switchInt) { case 0: System.out.print("Choose a number:\n1: discount\n2: buy bolts\n\n"); switchInt = r.readInt(); break; case 1: double origPrice; double discountPrice; System.out.print("Enter amount of purchases: "); origPrice = r.readDouble(); System.out.print("Discounted price: "); if (origPrice < 10.0) { System.out.print(dec.format(origPrice) + " (discounts only over 10 dollars)\n\n"); } else { discountPrice = origPrice - (origPrice * .1); System.out.print(dec.format(discountPrice) + " (discount of " + dec.format((origPrice * .1)) + ")\n\n"); } switchInt = 0; break; case 2: int bolts; int nuts; int washers; System.out.print("Number of bolts: "); bolts = r.readInt(); System.out.print("Number of nuts: "); nuts = r.readInt(); System.out.print("Number of washers: "); washers = r.readInt(); if (bolts != nuts) { System.out.print("\nCheck the Order\n\n"); } System.out.print("\nTotal cost: " + ((bolts * 5) + (nuts * 3) + (washers)) + "\n\n"); switchInt = 0; break; default: loop = false; break; } } while (loop == true); } }