Soal No 5 UTS PBO Kelas B menggunakan BlueJ.
Tanggal
Main
import java.util.Scanner;
/**
* Write a description of class Main here.
*
* @author (Ghannie Wijaya)
* @version (1.0)
*/
public class Main
{
public static void main(String args[])
{
Scanner scan= new Scanner(System.in);
int pilihan, pilihanlg, plh1, plh2;
boolean entry;
System.out.println("Selamat Datang. Silakan pilih menu berikut.");
System.out.println("1. Cetak struk ");
System.out.println("2. Bantuan ");
pilihan = scan.nextInt();
entry = true;
{
switch(pilihan)
{
case 1:
System.out.println("===================================");
System.out.println(" Berikut bukti struk parkir Anda ");
System.out.println("===================================");
System.out.println("Tanggal: 15 Oktober 2018 ");
System.out.println("Waktu: 14:23 ");
System.out.println("");
System.out.println("===================================");
System.out.println(" Jaga barang bawaan Anda ");
System.out.println("===================================");
break;
case 2:
System.out.println("===================================");
System.out.println(" Ada yang bisa kami bantu? ");
System.out.println("===================================");
System.out.println("1. Cara mencetak struk");
System.out.println("2. Biaya parkir");
pilihanlg=scan.nextInt();
{
if(pilihanlg == 1)
{
System.out.println("Tekan tombol hijau untuk mencetak.");
break;
}
if(pilihanlg == 2)
{
System.out.println("Motor = 1.000");
System.out.println("Mobil = 2.000");
break;
}
}
}
}
}
}
Tanggal
/**
* Write a description of class Tanggal here.
*
* @author (Ghannie Wijaya)
* @version (1.0)
*/
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class Tanggal{
private String getTanggal() {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
return dateFormat.format(date);
}
private String getWaktu() {
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
Date date = new Date();
return dateFormat.format(date);
}
public static void main(String Args[]){
Tanggal tgl = new Tanggal();
System.out.println("Sekarang tanggal : "+tgl.getTanggal());
System.out.println("Waktu sekarang : "+tgl.getWaktu());
}
}