java - How can I use an array variable to IF statement? -


i developing simple taxi meter calculator system. have no idea use implement it. have written code got stuck @ if statement had insert array variable. not sure whether correct way implement it.

this logic.

  • the first km 50/-.
  • then next 10km charged 45/- per km. eg : if 2km gone , charges 50/- + 45/- = 95/-, if 3km gone 140/-.
  • the next 10km charged 35/- per km
  • 25/- per km charged no matter how many kms gone after above 10km exceed.

this code have coded far

private void btn_calactionperformed(java.awt.event.actionevent evt) {                                                 int kms1 = 50;         int kms2 = 45;         int kms3 = 35;         int kms4 = 25;         string[] firstkm={"3,4,5,6,7,8,9,10,11"};         if(txt_km.gettext().equals("1")){             lblout.settext(""+kms1);         }         if(txt_km.gettext().equals("2")){             lblout.settext(""+(kms1+kms2));         }if(txt_km.gettext().equals(firstkm)){             int = integer.parseint(txt_km.gettext());             int rate = get+kms2;             lblout.settext(""+rate);         }  }   

if there other method solve problem please mention it.

int fare = 0; int distance = 0; if (distance > 21) {     fare += (distance - 21) * 25;     distance = 21; } if (distance > 11) {     fare += (distance - 11) * 35;     distance = 11; } if (distance > 1) {     fare += (distance - 1) * 45;     distance = 1; } if (distance > 0) {     fare += distance * 50; } 

then refactor putting magic numbers arrays , loop through arrays (4 times).


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -