0% found this document useful (0 votes)
24 views6 pages

Class Tugasmodul2 - Obat

The document contains code for a Java application that allows users to calculate medicine payments. The application contains three classes - TugasModul2_Obat which acts as the main class, MenuAwal which handles the initial menu, and hitung which contains the calculation logic. The hitung class calculates discounts and totals based on medicine type, quantity, and price. It allows the user to make multiple transactions by returning to the main menu after each one.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views6 pages

Class Tugasmodul2 - Obat

The document contains code for a Java application that allows users to calculate medicine payments. The application contains three classes - TugasModul2_Obat which acts as the main class, MenuAwal which handles the initial menu, and hitung which contains the calculation logic. The hitung class calculates discounts and totals based on medicine type, quantity, and price. It allows the user to make multiple transactions by returning to the main menu after each one.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like