1 TUGAS 1: WIN OR LOSE package kartu; import java.util.random; public class kartu { /** args the command line arguments */ public static void main(str...
/** * @param args the command line arguments */ public static void main(String adam_hidayat_markus[]) { Random acakacakan = new Random(); int kartu, total=0;
System.out.println("kartu total");
while (total<21){ kartu = acakacakan.nextInt(10)+1; total += kartu; System.out.print(" "); System.out.println(total); } if (total== 21){ System.out.println("Wih gila lu menang ^_^"); }else { System.out.print("Kasihan lu kalah T_T");
} } }
HASIL kartu total 5 8 9 11 21 Wih gila lu menang ^_^
TUGAS 2: ROLLED package dadu; import java.util.Random; import static java.lang.System.out;
public class dadu {
public static void main(String adam_hidayat_markus []) { Random acakadut = new Random(); int die1 = 0,die2 = 0; while (die1 + die2 !=9 && die2 !=11){ die1 = acakadut.nextInt(6)+1; die2 = acakadut.nextInt(6)+1; out.print(die1); out.print(" "); out.println(die2); } out.print("rolled "); out.println(die1 + die2); } }
HASIL 1 3 4 2 5 2
1 1 3 1 1 3 6 3 rolled 9
TUGAS 3: SYMBOL package symbol; import java.util.Scanner; public class symbol { public static void main(String[] adam_hidayat_markus) {
Scanner bentuk = new Scanner (System.in); char Symbol; Symbol = bentuk.findInLine(".").charAt(0); while (Symbol !='&'){ System.out.print(Symbol); Symbol = bentuk.findInLine(".").charAt(0); } System.out.println(); } }
HASIL &
TUGAS 5: PROGRAM ATM package atm; import java.util.Scanner; public class Atm { public static void main(String[] adam_hidayat_markus) { //variabel int menu, pilihan, pin, saldo=1000000; int tag1=175000, tag2=135000 , tag3=65000; Scanner SC = new Scanner (System.in); boolean go = true; boolean run = true; while (go==true) { while (run==true) {
//input
System.out.println("===PROGRAM ATM==="); System.out.println("masukkan pin anda ; "); pin = SC.nextInt(); if (pin != 170396){ System.out.println("PIN anda salah"); System.exit(0); }
System.out.println("=== MENU ATM ==="); System.out.println("1. Cek Saldo"); System.out.println("2. Tarik Tunai"); System.out.println("3. Transfer Tunai"); System.out.println("4. Pembayaran Tagihan"); System.out.println("5. Keluar"); System.out.println(); System.out.println("Masukkan Pilihan Anda :"); pilihan = SC.nextInt();
//PROSES
switch (pilihan){ case 1 : System.out.print("jumlah saldo anda : Rp."); System.out.println(saldo);break;
case 2 : System.out.println("masukkan jumlah : Rp."); int jumlah=SC.nextInt(); if (saldo-jumlah<=0){ System.out.print("Saldo Anda Kurang"); }else{ System.out.print("Sisa Saldo anda : Rp."); System.out.print(saldo-jumlah); }break; case 3 : System.out.print("Jumlah yang di Transfer : Rp."); int jumlah2=SC.nextInt();
if (saldo-jumlah2 <=0){ System.out.print("Saldo Anda Kurang!"); } else{ System.out.print("Sisa Saldo anda : Rp."); System.out.println(saldo-jumlah2); } break; case 4 : System.out.println("---Pilih Tagihan---"); System.out.println("6. Tagihan PLN"); System.out.println("7. Tagihan PDAM"); System.out.println("8. Tagihan TELKOM"); System.out.print("Masukkan Pilihan anda : "); int pil=SC.nextInt(); if (pil ==6){ System.out.println("Tagihan anda : Rp."+tag1); System.out.println("Apakah anda mau membayar ?"); System.out.print("9.[YA] / 10. [TIDAK] : "); int pill=SC.nextInt(); if (pill ==9){ System.out.println("Sisa saldo anda : Rp."+(saldo-tag1)); }else { System.out.println("Terima Kasih"); System.exit(0); } }else if (pil==7){ System.out.println("Tagihan anda : Rp."+tag2);
System.out.println("Apakah anda mau membayar ?"); System.out.print("9.[YA] / 10. [TIDAK] : "); int pill=SC.nextInt(); if (pill ==9){ System.out.println("Sisa saldo anda : Rp."+(saldo-tag2)); }else { System.out.println("Terima Kasih"); System.exit(0); } }else if (pil==8){ System.out.println("Tagihan anda : Rp."+tag3); System.out.println("Apakah anda mau membayar ?"); System.out.print("9.[YA] / 10. [TIDAK] : "); int pill=SC.nextInt(); if (pill ==9){ System.out.println("Sisa saldo anda : Rp."+(saldo-tag3)); }else { System.out.println("Terima Kasih"); System.exit(0); } } break; case 5 : System.out.println("Terima Kasih");
System.exit(0); default : System.out.println("Pilihan tidak ada");
run = false; } if (run==false) { System.out.println("kembali ke menu awal Y/N"); char again = SC.next().charAt(0);
if (again=='Y') { run = true; } else if (again == 'N') { System.out.println("good bye."); go = false; } else { System.out.println("pilihan tidak ada"); } } } } } }
HASIL run: ===PROGRAM ATM=== masukkan pin anda ; 170396 === MENU ATM === 1. Cek Saldo 2. Tarik Tunai 3. Transfer Tunai 4. Pembayaran Tagihan 5. Keluar
Masukkan Pilihan Anda : 1 jumlah saldo anda : Rp.1000000 ===PROGRAM ATM=== masukkan pin anda ;
TUGAS 4: BILANGAN GANJIL package ganjil;
public class Ganjil { public static void main(String adam_hidayat_markus[]){ int i = 1, ganjil = 1, jumlah = 0;
while (i <= 4){ System.out.println(i+". "+ganjil); jumlah += ganjil; ganjil = ganjil+2; i++; } System.out.println("J u m l a h => "+jumlah); } }