My switch statement is not running (It was working yesterday but IDK what happened) JAVA -


i dont know did hen run main program not going through switch statement. working last night , haven't changed in anyway added print statement debugging purposes. apart of pos system have class assignment.

package multibuy;  import static pos.pos_system.nongstvodka; import static pos.pos_system.price_format; import static pos.pos_system.vodka; import static pos.pos_system.btncancelprevious; import static pos.pos_system.npreviousprice; import static pos.pos_system.ntotal; import static pos.pos_system.strpreviousdrink; import static pos.pos_system.txtbill; import static pos.pos_system.spaces;  public class multibuy {      public static int clicked;     public static double discountamt = 0.05;     public static double discount_price_vodka = 0.385;     public static double newvodkaprice;      public static void multibuy(){                          pos.pos_system.btnvodkapressed = true;                          system.out.println("no cases ran");                  switch(clicked){                  case 1:                      if(clicked == 0){                      //plus 1 clicked create event                          clicked++;                                  system.out.println("case 1 completed");                                  break;                     }                  case 2 :                      if(clicked >= 2 && pos.pos_system.btnvodkapressed == true){                                      txtbill.settext(txtbill.gettext() + "\n" +                     "     " + strpreviousdrink +                      spaces(40 - strpreviousdrink.length()) + "-" +                     price_format.format(npreviousprice) + "\n" +  "     (canceled)\n");                 ntotal -= npreviousprice + newvodkaprice;                 btncancelprevious.setenabled(false);                      newvodkaprice = vodka - discount_price_vodka;                      pos.pos_system.txtbill.settext(pos.pos_system.txtbill.gettext() + "\n" + "multibuy special = " + multibuy.discount_price_vodka);                                  pos.pos_system.txtbill.settext(pos.pos_system.txtbill.gettext() + "new price = " + newvodkaprice);                                  pos.pos_system.ntotal = pos.pos_system.ntotal;                      clicked--;                                  system.out.println("case 2 completed");//should equal 3                                  break;                                  }                         case 3 :                                  if(clicked <= 1){                                  clicked++;                                  system.out.println("case 3 completed");//should equal 2                                  break;                                  }                  }             }         } 

there couple issues first. notably, never initialized property (or private instance variable) of clicked, maybe elsewhere? probably needs done in constructor (the job of constructor initialize private instance variables). can see, integer (a primitive type) 0. anyway, don't believe you're utilizing switch statement correctly. switch nothing more syntactical candy if statements.

for example, following code blocks identical

if statement:

public int foo = 0; if(foo == 1) {     // things } else if (foo == 2) {    // things } else {    // things } 

switch:

public int foo = 0; switch(foo) {     case 1:           // things          break;     case 2:           // things          break;     default:          // things          break; } 

the reason break keyword being crucial in java explained here if know that.

note in java can switch on variable int. other languages allow switch on primitive types , custom objects! moving on...

for these reasons, switch statements wrote never processed, if blocks irrelevant , never execute way have setup. can tell, here edited code block think want happen (though can't tell want do). given explained above, however, i'm sure can work out more ease.

// imports  public class multibuy {      public static int clicked;     public static double discountamt = 0.05;     public static double discount_price_vodka = 0.385;     public static double newvodkaprice;      public static void multibuy(){         pos.pos_system.btnvodkapressed = true;         system.out.println("no cases ran");          // initialize clicked!!!!           clicked = 3;          switch(clicked){             case 0:             clicked++;             system.out.println("case 1 completed");             break;              default:               txtbill.settext(txtbill.gettext() + "\n" +                     "     " + strpreviousdrink +                      spaces(40 - strpreviousdrink.length()) + "-" +                     price_format.format(npreviousprice) + "\n" +  "     (canceled)\n");                 ntotal -= npreviousprice + newvodkaprice;                 btncancelprevious.setenabled(false);                 newvodkaprice = vodka - discount_price_vodka;                 pos.pos_system.txtbill.settext(pos.pos_system.txtbill.gettext() + "\n" + "multibuy special = " + multibuy.discount_price_vodka);                 pos.pos_system.txtbill.settext(pos.pos_system.txtbill.gettext() + "new price = " + newvodkaprice);                 pos.pos_system.ntotal = pos.pos_system.ntotal;                 clicked--;                 system.out.println("case 2 completed");//should equal 3             break;         }     } } 

hope helped :)


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -