import java.util.Scanner; import java.text.DecimalFormat; public class GirlScoutCookies {     public static int Count1s, Count2s, Count3s, Count4s, Count5s = 0;     public static String Cookie1 = "Thin Mints";     public static String Cookie2 = "Tagalongs";     public static String Cookie3 = "Lemon Doodles";     public static String Cookie4 = "Do-Si-Dos";     public static String Cookie5 = "Samoas";     public static double Price1 = 4.99;     public static double Price2 = 4.50;     public static double Price3 = 5.99;     public static double Price4 = 4.71;     public static double Price5 = 4.03;     public static DecimalFormat df = new DecimalFormat("#.00");     public static Scanner scan = new Scanner(System.in);     public static int intCookieChoice = 0;     public static int intQuantity = 0;     /**      * @param args the command line arguments      */     public static void main(String[] args) {         // TODO code application logic here         System.out.println("Would you like to order some Girl Scout Cookies?");         String strYorN = scan.nextLine();         while ((!strYorN.equalsIgnoreCase("yes"))                 && (!strYorN.equalsIgnoreCase("no"))) {             System.out.println("I'm sorry, but you must reply with a 'yes' or a 'no'.");             strYorN = scan.nextLine();         }         if (strYorN.equalsIgnoreCase("no")) {             System.out.println("Thanks anyway. Maybe next time.");             System.exit(0);         }         boolean NeedToUpdateOrder = true;         while (NeedToUpdateOrder) {             DisplayCookieListAndPrices();             AskWhichOneAndQty();             Accumulate();             DisplayCurrentOrder();             /* TO-DO: Ask if any changes.             Prompt the user if the order is complete.  If it IS complete,             then set the sentinel NeedToUpdateOrder to falss to get us out of the             big loop.  Otherwise, set the sentinel NeedToUpdateOrder to true to             keep us in the loop.  Once this is done, you can remove the next line of             code.             */             NeedToUpdateOrder = false; // stop after just one for now...         }     }     public static void DisplayCookieListAndPrices() {         System.out.println("1. " + Cookie1 + " $" + df.format(Price1));         System.out.println("2. " + Cookie2 + " $" + df.format(Price2));         System.out.println("3. " + Cookie3 + " $" + df.format(Price3));         System.out.println("4. " + Cookie4 + " $" + df.format(Price4));         System.out.println("5. " + Cookie5 + " $" + df.format(Price5));     }     public static void AskWhichOneAndQty() {         intCookieChoice = 0;    // reset the value from the last time this variable was set.         intQuantity = 0;        // reset the value from the last time this variable was set.         while (intCookieChoice <= 0 || intCookieChoice >= 6) {             System.out.println("Which type of cookie would you like to buy? ");             String strCookieChoice = scan.nextLine();             try {                 // the String to int conversion happens here                 intCookieChoice = Integer.parseInt(strCookieChoice.trim());                 if (intCookieChoice >= 1 && intCookieChoice <= 5) {                     // we know they chose a valid menu item so we can continue                     // on below...  Did you notice how this is an example of how                     // you can have a block of code that                     // actually doesn't have any statements in it?  All that is                     // in this code block is this comment block!                 } else {                     System.out.println("You selected an invalid menu item.  Please re-enter.");                     DisplayCookieListAndPrices();                 }             } catch (NumberFormatException nfe) {                 System.out.println("Please enter only a valid menu item number between 1 and 5.");                 DisplayCookieListAndPrices();             }             while (intQuantity == 0) { // Notice how I am using the quantity of zero                 // as my sentinel.  If the user keys a zero for                 // the quantity, then s/he is actually NOT                 // adjusting the order at all.  So a zero                 // might be considered an invalid entry... so                 // we will keep in this loop until we get a non-zero                 // entry.                 System.out.println("How many boxes of that cookie would you like to buy?\n"                         + "(Enter positive whole numbers for boxes to ADD to the order or\n"                         + "enter negative whole number for boxes to REMOVE from the order.");                 String strQuantity = scan.nextLine();                 try {                     // the String to int conversion happens here                     intQuantity = Integer.parseInt(strQuantity.trim());                     if (intQuantity != 0) {                         // we know they chose a valid (non-zero integer) quantity                     } else {                         System.out.println("Please enter only a valid quantity (e.g. a non-zero whole number.)");                     }                 } catch (NumberFormatException nfe) {                     System.out.println("Please enter only a valid quantity (e.g. a non-zero whole number.)");                 }             }         }     }          public static void Accumulate(){         /*         TO-DO: Write the code to use the two variables intCookieChoice and intQuantity         to adjust the appropriate variables Count1s, Count2s, etc.  This will end         up being either a series of if-then-elses or a switch block.         Also please make sure you handle if they try to reduce a counter BELOW         zero (e.g. negative) and then only set it equal to zero and give them an         appropriate message that you limited the reduction.         */     }          public static void DisplayCurrentOrder(){         /*         TO-DO: Write the code to print out each of the 5 Cookie types and the         current quantity that is being ordered and the computation of the extended         cost for each cookie (e.g. quantity * price).  Then, at the end, print         the current grand total for the order so far.  Make sure the totals that         are computed are printed with correct formatting as I have done above.         */     } }