Kamis, 03 November 2011

Tugas Java "Jasa Pengiriman Barang"

import java.util.*;

class Barang{
private String kota;
private int harga;
    private double potongan,total;
   
   
void ProsesIf(String kode){
   if(kode.equals("jogja"))
   harga=10000;
 
   else if(kode.equals("surabaya"))
   harga=15000;
   else
   harga=20000;
}
int Ambil(){
return harga;
}

void Bayar(int berat){
total=harga*berat;
}
double Take(){
return total;
}

void Pot(int berat){
if(berat>10)
potongan=total*0.05;
else
potongan=0;
}
double Get(){
return potongan;
}

double Akhir(){
return total-potongan;
}
}

public class Pengiriman {
public static void main(String[] args) {
Scanner masuk=new Scanner(System.in);
Barang brg=new Barang();

String kota;
int berat;
double TotalBayar;

    System.out.println("JASA PENGIRIMAN BARANG");
    System.out.println("=======================");

System.out.print("Kode Barang [Jogja/Surabaya/Bali] : ");kota=masuk.nextLine();
brg.ProsesIf(kota);
System.out.println("Ongkos Kirim per Kg : "+brg.Ambil());
System.out.print("Berat Paket [Kg] : ");berat=masuk.nextInt();
brg.Bayar(berat);
System.out.println("Total : "+brg.Take());
brg.Pot(berat);
System.out.println("Potongan : "+brg.Get());
TotalBayar=brg.Akhir();
System.out.println("Total Bayar : "+TotalBayar);
}
}

Tidak ada komentar:

Poskan Komentar