Last active
November 13, 2015 07:29
-
-
Save ardianta/5e2974b064b571b5975e to your computer and use it in GitHub Desktop.
Contoh percabangan bersarang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pertemuan6; | |
import javax.swing.JOptionPane; | |
public class Kasir { | |
public static void main(String[] args) { | |
// deklarasi | |
int belanjaan, diskon, bayar; | |
String kartu; | |
// input | |
kartu = JOptionPane.showInputDialog("Apakah ada kartu member?"); | |
belanjaan = Integer.valueOf(JOptionPane.showInputDialog("Total belanjaan?")); | |
// proses | |
if (kartu.equalsIgnoreCase("ya")) { | |
if (belanjaan > 500000) { | |
diskon = 50000; | |
} else if (belanjaan > 100000) { | |
diskon = 15000; | |
} else { | |
diskon = 0; | |
} | |
} else { | |
if (belanjaan > 100000) { | |
diskon = 5000; | |
} else { | |
diskon = 0; | |
} | |
} | |
// total yang harus dibayar | |
bayar = belanjaan - diskon; | |
// output | |
JOptionPane.showMessageDialog(null, "Total bayar: Rp " + bayar); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment