UTS
UTS
souce code dan class :
souce code dan class :
- tiketElektronik
- main
/**
* Write a description of class parkirElektronik here.
*
* @author (Nitama Nurlingga)
* @version (2018)
*/
public class parkirElektronik
{
private String platnomor;
private int jenis;
private int durasi;
private int total;
public parkirElektronik(String plat)
{
platnomor = plat;
jenis = 0;
durasi = 0;
}
public String getPlatnomor()
{
return platnomor;
}
public int getJenis(int jenis)
{
return jenis;
}
public int getDurasi(int durasi)
{
return durasi;
}
public void printKarcis()
{
System.out.println("===DINAS PERHUBUNGAN===\n");
System.out.println("===KOTA SURABAYA===\n");
System.out.print("Jenis kendaraan : ");
if(jenis == 1)
{
System.out.println("Motor\n");
}
else if(jenis==2)
{
System.out.println("Mobil\n");
}
else if(jenis == 3)
{
System.out.println("Sepeda\n");
}
System.out.println("Durasi : " +durasi+"menit\n");
System.out.print("Tarif parkir : ");
if(jenis == 1)
{
System.out.println("Rp 2000\n");
}
else if(jenis==2)
{
System.out.println("Rp 5000\n");
}
else if(jenis == 3)
{
System.out.println("Rp 1000\n");
}
System.out.print("Total : ");
if(jenis == 1)
{
if(durasi<60)
total = 2000;
else
{
total = (durasi/60)*2000;
System.out.println("Rp "+total+"\n");
}
}
else if(jenis==2)
{
if(durasi<60)
total = 5000;
else
{
total = (durasi/60)*5000;
System.out.println("Rp "+total+"\n");
}
}
else if(jenis == 3)
{
if(durasi<60)
total = 1000;
else
{
total = (durasi/60)*1000;
System.out.println("Rp "+total+"\n");
}
}
}
}
import java.util.Scanner;
/**
* Write a description of class Main here.
*
* @author (Nitama Nurlingga)
* @version (2018)
*/
public class Main
{
public static void main (String args[])
{
Scanner scan = new Scanner(System.in);
String platnomor;
int jenis;
int durasi;
int menu;
int printkarcis;
boolean start;
System.out.println("Selamat datang di parki elektronik Taman Bungkul\n");
System.out.println("Silahkan masukkan nomor kendaraan anda: ");
platnomor = scan.nextLine();
parkirElektronik parkir = new parkirElektronik(platnomor);
start = true;
while (start)
{
System.out.println("Silahkan masukkan jenis kendaraan anda: \n");
System.out.println("1. Motor : Rp 5000/jam\n");
System.out.println("2. Mobil : Rp 2000/jam\n");
System.out.println("3. Sepeda : Rp 1000/jam\n");
jenis = scan.nextInt();
parkir.getJenis(jenis);
System.out.println("Silahkan masukkan durasi parkir yang diinginkan(menit): \n");
durasi = scan.nextInt();
parkir.getDurasi(durasi);
System.out.println("Silakan tempel kartu untuk membayar\n");
System.out.println("Tekan 1 untuk melanjutkan\n");
printkarcis = scan.nextInt();
if (printkarcis ==1)
{
parkir.printKarcis();
}
start = false;
}
}
}
Komentar
Posting Komentar