The if statement always use the first condition

Viewed 30

I have a program that aplly discount, but its always apply the first condition. The condition is : if the value is over 300000 it will aplly 3% discount, and if the value is over than 500000 it will aplly 5%, but in my program it always apply the first condition (the 3%) although the value is over 500000. Please help, there's my code:

if(kb.equals("A")){
   nama_buah.setText("Anggur");
   hargakg.setText("47000");
   String anggur="47000";
   int hrganggur=Integer.parseInt(anggur);
   thargaanggur=hb*hrganggur;
   harga.setText(Integer.toString(thargaanggur));
   if(thargaanggur >= 300000){
       int totaldiskon,totalbayar;
       totaldiskon=thargaanggur*3/100;
       diskon.setText("Diskon 3% = " + totaldiskon);
       totalbayar=thargaanggur-totaldiskon;
       total_seluruh.setText(Integer.toString(totalbayar));
   }
   else if(thargaanggur >= 500000){
       int totaldiskon,totalbayar;
       totaldiskon=thargaanggur*5/100;
       diskon.setText("Diskon 5% = " + totaldiskon);
       totalbayar=thargaanggur-totaldiskon;
       total_seluruh.setText(Integer.toString(totalbayar));
   }
   else{
       total_seluruh.setText(Integer.toString(thargaanggur));
1 Answers

Just change their order. If a value is larger than 500000, it's also larger than 300000. Always. The opposite is not always true

Related