it's always going to default in my switch java -


import java.util.scanner; import java.text.decimalformat; import java.util.locale; import java.text.*; import javax.swing.joptionpane;  public class project4b {   private static final float bagel = 2.00f, donut = 1.50f, croissant = 3.00f;   private static final float latte = 1.50f, coffee = 1.25f, milk = 1f, tea = 0.50f;   private static int choice, choice2;   private static int inflav;   private static string flavorstring;    public static void main(string[] args) {     numberformat moneyformat = numberformat.getcurrencyinstance(locale.us);      /* string flavorstring int inflav */      string str1 = joptionpane.showinputdialog(null,         "welcome bebe's best breakfast \nchoose breakfast item:\n1 bagel @ " + moneyformat.format(bagel) + "\n2 donut @ " + moneyformat.format(donut) +             "\n3 croissant @ " + moneyformat.format(croissant),         "input", joptionpane.question_message);     choice = integer.parseint(str1);     switch (choice == 1) {     case 1:       flavorstring = ": onion ";       string flavorstring = joptionpane.showinputdialog(null, "choose flavor bagel\n1 onion\n2 blueberry \n3 rye", "input", joptionpane.question_message);       break;      case 2:       flavorstring = ": blueberry ";       joptionpane.showinputdialog(null, "choose flavor bagel\n1 onion\n2 blueberry \n3 rye", "input", joptionpane.question_message);       break;     case 3:       flavorstring = ": rye ";       joptionpane.showinputdialog(null, "choose flavor bagel\n1 onion\n2 blueberry \n3 rye", "input", joptionpane.question_message);       break;     default:       flavorstring = ": plain ";       joptionpane.showinputdialog(null, "choose flavor donut\n1 onion\n2 blueberry \n3 rye", "input", joptionpane.question_message);     }      if (choice == 2) {       switch (inflav) {       case 1:         flavorstring = ": jelly ";         joptionpane.showinputdialog(null, "choose flavor donut\n1 jelly\n2 chocolate\n3 sprinkles\n4 cinnamon ", "input", joptionpane.question_message);         break;       case 2:         flavorstring = ": chocolate ";         joptionpane.showinputdialog(null, "choose flavor donut\n1 jelly\n2 chocolate\n3 sprinkles\n4 cinnamon ", "input", joptionpane.question_message);         break;       case 3:         flavorstring = ": sprinkles ";         joptionpane.showinputdialog(null, "choose flavor donut\n1 jelly\n2 chocolate\n3 sprinkles\n4 cinnamon ", "input", joptionpane.question_message);         break;       case 4:         flavorstring = ": cinnamon ";         joptionpane.showinputdialog(null, "choose flavor donut\n1 jelly\n2 chocolate\n3 sprinkles\n4 cinnamon ", "input", joptionpane.question_message);         break;       default:         flavorstring = ": plain ";         joptionpane.showinputdialog(null, "choose flavor donut\n1 jelly\n2 chocolate\n3 sprinkles\n4 cinnamon ", "input", joptionpane.question_message);       }     }      inflav = integer.parseint(flavorstring);      string str2 = joptionpane.showinputdialog(null,         "choose 1 of following beverages: \nenter:\n1 latte @ " + moneyformat.format(latte) + "\n2 coffee @ " + moneyformat.format(coffee) +             "\n3 milk @ " + moneyformat.format(milk) + "\n4 tea @" + moneyformat.format(tea),         "input", joptionpane.question_message);     choice2 = integer.parseint(str2);      system.out.println("how many of these items like<1 20>");     scanner office = new scanner(system.in);     int office1;     office1 = office.nextint();      float bageltotal = (bagel * office1);     float donuttotal = (donut * office1);     float croissanttotal = (croissant * office1);     float lattetotal = (latte * office1);     float coffeetotal = (coffee * office1);     float milktotal = (milk * office1);     float teatotal = (tea * office1);      float cost1 = 0.0f;      string choicestr = "";     if (choice == 1) {       cost1 = bagel;       choicestr = ("bagel @ ");     } else if (choice == 2) {       cost1 = donut;       choicestr = ("donut @ ");     } else if (choice == 3) {       cost1 = croissant;       choicestr = ("croissant @ ");      }      float cost2 = 0.0f;     string choicestr2 = "";     if (choice2 == 1) {       cost2 = latte;       choicestr2 = ("latte @ ");     } else if (choice2 == 2) {       cost2 = coffee;       choicestr2 = ("coffee @ ");     } else if (choice2 == 3) {       cost2 = milk;       choicestr2 = ("milk @ ");     } else if (choice2 == 4) {       cost2 = tea;       choicestr2 = ("tea @ ");     }     float totalcost = (cost1 * office1);     float total2cost = (cost2 * office1);     float lowtotal = (cost1 + cost2);     float completetotal = (totalcost + total2cost);      joptionpane.showmessagedialog(null,         ("breakfast ordered:\n" + choicestr + flavorstring + moneyformat.format(cost1) + "\n\nbeverage ordered: \n" + choicestr2 + moneyformat.format(cost2) + "\n\ntotal cost: "             + moneyformat.format(lowtotal) + "\n\nnumber ordered: " + office1 + "\n\ntotal due: " + moneyformat.format(completetotal)),         "your bill", joptionpane.information_message);    } } 

hi java1 homework. problem i'm trying flavor show on joption output yourbill. defaults default in switch. can't see figure out why. thought i'd take break , see if had suggestions. thanks

you have bug here:

switch (choice ==1){ 

it should be:

switch (choice){ 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -