import java.util.*; public class SimpleCart { public static void main(String[]args) { Scanner stdIn = new Scanner(System.in); String itemName1, itemName2, itemName3; int itemCost1, itemCost2, itemCost3; int itemQty1, itemQty2, itemQty3; int totalCost = 0; System.out.print("Enter item name: "); itemName1 = stdIn.nextLine(); System.out.print("Enter cost for each item: "); itemCost1 = stdIn.nextInt(); System.out.print("Enter quantity: "); itemQty1 = stdIn.nextInt(); totalCost = itemCost1*itemQty1; System.out.print("Do you wish to add more items? (y/n): "); String yesOrNo = stdIn.next(); stdIn.nextLine(); if (yesOrNo.equals("n")) { if ((totalCost%100 != 0) && (totalCost%100 > 10)) { System.out.println("Total: $" + totalCost/100 + "." + totalCost%100); } else if ((totalCost%100 != 0) && (totalCost%100 < 10)) { System.out.println("Total: $" + totalCost/100 + ".0" + totalCost%100); } else if (totalCost%100 == 0) { System.out.println("Total: $" + totalCost/100 + ".00"); } } else if (yesOrNo.equals("y")) { System.out.print("Enter item name: "); itemName2 = stdIn.nextLine(); System.out.print("Enter cost for each item: "); itemCost2 = stdIn.nextInt(); System.out.print("Enter quantity: "); itemQty2 = stdIn.nextInt(); totalCost = ((itemCost2*itemQty2) + (itemCost1*itemQty1)); System.out.print("Do you wish to add more items? (y/n): "); String response = stdIn.next(); stdIn.nextLine(); if (response.equals("n")) { if ((totalCost%100 != 0) && (totalCost%100 > 10)) { System.out.println("Total: $" + totalCost/100 + "." + totalCost%100); } else if ((totalCost%100 != 0) && (totalCost%100 < 10)) { System.out.println("Total: $" + totalCost/100 + ".0" + totalCost%100); } else if (totalCost%100 == 0) { System.out.println("Total: $" + totalCost/100 + ".00"); } } else if (response.equals("y")) { System.out.print("Enter item name: "); itemName3 = stdIn.nextLine(); System.out.print("Enter cost for each item: "); itemCost3 = stdIn.nextInt(); System.out.print("Enter quantity: "); itemQty3 = stdIn.nextInt(); totalCost = ((itemCost3*itemQty3) + (itemCost2*itemQty2) + (itemCost1*itemQty1)); if ((totalCost%100 != 0) && (totalCost%100 > 10)) { System.out.println("Total: $" + totalCost/100 + "." + totalCost%100); } else if ((totalCost%100 != 0) && (totalCost%100 < 10)) { System.out.println("Total: $" + totalCost/100 + ".0" + totalCost%100); } else if (totalCost%100 == 0) { System.out.println("Total: $" + totalCost/100 + ".00"); } } } } } //eof