CLASS TugasModul2_Obat
package obat;
import java.io.IOException;
/**
*
* @author Balung
*/
public class TugasModul2_Obat {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
MenuAwal ma = new MenuAwal();
ma.milih();
}
CLASS MenuAwal
package obat;
import java.io.*;
/**
*
* @author Balung
*/
public class MenuAwal {
public void milih() throws IOException{
try{
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Aplikasi Pembayaran Obat ");
System.out.println("1. Pembayaran Obat");
System.out.println("2. Keluar");
System.out.println("====================");
System.out.println("Pilih Nomer : 1/2");
int pilih=Integer.parseInt(b.readLine());
System.out.println("====================");
hitung h = new hitung();
h.setPilih(pilih);
} catch (Exception e){
System.out.println("Error : "+e);
}
}
}
CLASS hitung
package obat;
import java.io.*;
/**
*
* @author Balung
*/
public class hitung {
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
MenuAwal ma=new MenuAwal();
private String kodeObat, namaObat,keterangan,hd;
private int jenisObat,pilih;
private double hargaTotal,hargaSementara;
void setPilih(int pilih) throws IOException {
this.pilih = pilih;
this.prosesPilih();
}
void pilihanJenisObat(){
System.out.println("Pilih Jenis Obat :");
System.out.println("1. Umum");
System.out.println("2. Bebas Terjual");
System.out.println("3. Dengan Resep");
System.out.println("=================");
}
void hitungDiskon(double hargasatuan, double jml){
hargaSementara=(hargasatuan*jml);
double dis=0;
if(jenisObat==1){
dis=(hargaSementara*1)/100;
} else if (jenisObat ==2){
dis=(hargaSementara*2)/100;
} else if (jenisObat ==3){
dis=(hargaSementara*3)/100;
}
System.out.println("Diskon
: Rp. "+dis);
this.hitungTotal(dis);
}
void hitungTotal(double dis){
hargaTotal=hargaSementara - dis;
System.out.println("Harga total : Rp. "+hargaTotal);
}
public void prosesPilih() throws IOException{
try {
if (pilih ==1){
System.out.print("Masukkan kode obat
: ");
kodeObat = b.readLine();
System.out.print("Masukkan nama obat
: ");
namaObat = b.readLine();
this.pilihanJenisObat();
jenisObat = Integer.parseInt(b.readLine());
System.out.print("Keterangan
: ");
keterangan = b.readLine();
System.out.print("Jumlah
: ");
int jml = Integer.parseInt(b.readLine());
System.out.print("Harga satuan : ");
double hargasatuan = Double.parseDouble(b.readLine());
this.hitungDiskon(hargasatuan, jml);
System.out.println("Apakah anda masih ingin bertransaksi lagi? y/n");
hd=b.readLine();
if(hd.equals("y")){
System.out.println("==============================");
System.out.println("------------------------------");
ma.milih();
}else {
System.exit(0);
}
}else {
System.out.println("Salah Masukkkan nomer pilihan");
}
} catch (Exception e){
System.out.println("Error "+e);
}
}
}
SCREENSHOOT