ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 28 Apr 2017 My Price 11.00

NetBeans- Java syntax

Hello. I am working on a project using NetBeans- Java syntax. My project is prompting the user if they would like to order Girl Scout Cookies, which kind of cookie, the quantity, if they have any changes, and then outputs what they are buying and the grand total. I have added comments and TODOs is the appropriate areas where I need help!

 

 

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. */ } }

Attachments:

Answers

(11)
Status NEW Posted 28 Apr 2017 03:04 AM My Price 11.00

-----------

Attachments

file 1493348665-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)
Relevent Questions