pada class pertama (AppSpbu) :
package com.pbo.project;
public class AppSpbu {
//set global variable
private static int pilihan = 1;
public static void main(String[] args){
do{
//initialized class
Request r1 = new Request();
//call showChoice method from class Request
r1.showChoice();
//print output from toString method in class Request
System.out.println(r1);
//set "pilihan" from result of tryAgain method
pilihan = r1.tryAgain();
}while(pilihan == 1);
}
}
kemudian pada class kedua yaitu class Request :
package com.pbo.project;
import java.util.Scanner;
/**
*
* @author Dwiky
*/
public class Request {
//set global variable
int transType, type;
double liter, price;
int priceDef[] = {20000, 11500, 9900, 4500, 5500};
String listType[] = {"Pertamax DEX", "Pertamax Plus", "Pertamax", "Premium", "BioSolar"};
Scanner input;
public void showChoice(){
input = new Scanner(System.in);
System.out.println("\n\nWelcome to SPBU 31-123456\n\nJenis Bahan Bakar");
System.out.println("1. Pertamax DEX\t\tRp 20,000\n2. Pertamax Plus\tRp 11,500\n3. Pertamax\t\tRp 9,900\n4. Premium\t\tRp 4,500\n5. BioSolar\t\tRp 5,500");
System.out.print("Masukkan pilihan anda (1-5): ");
type = input.nextInt(); //input type
System.out.print("\nPembelian berdasarkan :\n1. Liter\n2. Biaya\nMasukkan pilihan anda (1-2) : ");
transType = input.nextInt(); //input type transaction
if(transType == 1){
System.out.print("Masukkan jumlah liter (l): ");
liter = input.nextInt(); //input liter
calculateReq(type);
}else if(transType == 2){
System.out.print("Masukkan jumlah harga (Rp): ");
price = input.nextInt(); //input price
calculateReq(type);
}
}
public void calculateReq(int tipe){
if(transType == 1){
price = liter * priceDef[type - 1];
}else if(transType == 2){
liter = price / priceDef[type - 1];
}
}
public int tryAgain(){
System.out.print("Apakah anda ingin melakukan transaksi lagi? (Y/N) : ");
Scanner inputan = new Scanner(System.in);
String jawab = inputan.nextLine();
if(jawab.toUpperCase().contentEquals("Y"))
return 1;
else
return 0;
}
@Override
public String toString() {
return "\n\nHasil Perhitungan\nJenis Bahan Bakar :\t" + listType[type - 1]
+ "\nJumlah Liter :\t" + liter
+ "\nJumlah Harga :\t" + price;
}
}
Kelompok
1. http://ryuuzeo-taros.blogspot.com/ (Dani Pernando)
2. http://fika4194.blogspot.com/ (Fika Hadi)
3. http://jenniyuslauw.blogspot.com/ (Jenniyus)
4. http://the-revolution-of-ezhie.blogspot.com/ (Verry )
Tidak ada komentar:
Posting Komentar