jump to navigation

Latihan Penggunaan Fungsi Scanner di Java December 23, 2011

Posted by kelompok24itbseamolecb5 in Pemrograman Java.
trackback

Tugas1 Pembuatan Class Menu ATM menggunakan Fungsi Scanner

import java.util.Scanner;

public class atm {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Scanner s =new Scanner(System.in);

BankAccont bank= new BankAccont();

int input;

//saldo=100000;

while(true){

System.out.println(“Menu ATM”);

System.out.println(“1.Cek Saldo  2.Simpan Uang    3.Ambil Uang    4.Keluar”);

System.out.println(“Silahkan Masukan Pilihan Anda?”);

System.out.println(“——————————————————“);

input=s.nextInt();

if(input==1){

System.out.println(“Saldo sekarang:Rp: ” +bank.cek() );

}else if(input==2){

System.out.print(“Masukan Nominal:Rp”);

input=s.nextInt();

//saldo=saldo+input;

System.out.println(“Saldo Anda Sekarang:Rp”+bank.simpan(input));

}else if(input==3){

System.out.print(“Masukan Nominal:Rp”);

input=s.nextInt();

//saldo=saldo-input;

System.out.println(“Saldo Anda Sekarang:Rp”+bank.ambiluang(input));

}else if(input==4){

//System.out.println(“Keluar Aplikasi”);

//System.exit(1);

bank.keluar();

}

}

}

}

public class BankAccont {

private  int saldo;

public BankAccont(){

saldo=100000;

}

public int cek(){

return saldo;

}

public int simpan(int input){

saldo=saldo+input;

return saldo;

}

public int ambiluang(int input){

saldo=saldo-input;

return saldo;

}

public void keluar(){

System.out.println(“Keluar Aplikasi”);

System.exit(1);

}

}

 

Tugas2 Pembuatan Class Menu Restoran menggunakan Fungsi Scanner
import java.util.Scanner;public class MenuRestoran {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int uangKembalian, uangBayar, pilihan, hrgNasiGoreng, hrgNasiRawon, hrgNasiGudeg, hrgJusJeruk, total = 0;

boolean kondisi = false;

System.out.println(“Menu RESTORAN Kelompok24”);

System.out.println(“1.Nasi Goreng 2.Nasi Rawon    3.Nasi Gudeg   4.Jus Jeruk”);

System.out.println(“5.Hitung Total 6.Keluar Aplikasi”);

System.out.println(“Silahkan Masukan Pilihan Anda?”);

System.out.println(“——————————————————“);

pilihan = input.nextInt();

while (kondisi == false) {

switch (pilihan) {

case 1:

hrgNasiGoreng = 15000;

total += hrgNasiGoreng;  //total=total+hargnasigoreng;

System.out.print(“Pilih Menu Lainnya:”);

pilihan = input.nextInt();

break;

case 2:

hrgNasiRawon = 15000;

total += hrgNasiRawon;

System.out.print(“Pilih Menu Lainnya:”);

pilihan = input.nextInt();

break;

case 3:

hrgNasiGudeg = 15000;

total += hrgNasiGudeg;

System.out.print(“Pilih Menu Lainnya:”);

pilihan = input.nextInt();

break;

case 4:

hrgJusJeruk = 15000;

total += hrgJusJeruk;

System.out.print(“Pilih Menu Lainnya:”);

pilihan = input.nextInt();

break;

case 5:

System.out.println(“Total Harga =” + total);

System.out.println(“Uang Yang Dibayarkan:”);

uangBayar = input.nextInt();

uangKembalian = uangBayar – total;

System.out.println(“Kembaliannya:” + uangKembalian);

kondisi = true;

break;

case 6:

System.exit(0);

break;

}

}

}

}

 

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: