0% found this document useful (0 votes)
632 views8 pages

Source Code (Program Perhitungan Parkir)

This document contains the source code for a parking fee calculation program written in Java. The program prompts the user to input their vehicle registration number, entry time, exit time, and vehicle type. It then calculates the parking duration in hours and determines the fee based on the vehicle type, outputting the parking data to a text file. The program was created by three students for a university course assignment and includes exception handling for invalid user inputs.

Uploaded by

Abdul Haqeem
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)
632 views8 pages

Source Code (Program Perhitungan Parkir)

This document contains the source code for a parking fee calculation program written in Java. The program prompts the user to input their vehicle registration number, entry time, exit time, and vehicle type. It then calculates the parking duration in hours and determines the fee based on the vehicle type, outputting the parking data to a text file. The program was created by three students for a university course assignment and includes exception handling for invalid user inputs.

Uploaded by

Abdul Haqeem
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
You are on page 1/ 8

SOURCE CODE PROGRAM

PROGRAM PERHITUNGAN PARKIR

NAMA ANGGOTA :
ABDUL HAQEEM (202010370311302)
ANDHANA SEPTIAN SALIM (202010370311309)
DEVI APRILYA DINANTHI (202010370311297)

PROGRAM STUDI TEKNIK INFORMATIKA


FAKULTAS TEKNIK
UNIVERSITAS MUHAMMADIYAH MALANG
2020/2021
Source Code :

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.*;

public class dataparkir2 {

private int tarif_Parkir=0;


private int total_Jam_Parkir;
private int jam_masuk;
private int jam_keluar;
private String No_Polisi;
boolean lanjut=true;

Scanner input = new Scanner(System.in);

public String No_polisi(){


return No_Polisi;
}
public void setNo_polisi(){

System.out.println("========================================");
System.out.println("=======PROGRAM PERHITUNGAN PARKIR=======");
System.out.println("========================================");
System.out.print("Masukan No Polisi kendaraan Anda : ");
No_Polisi = input.next();

public int getjam_masuk() {


return jam_masuk;
}

public void setjam_masuk() {


do{
try {
System.out.print("Masukan Jam Masuk : ");
jam_masuk = input.nextInt();

if(jam_masuk > 0){

}
if(jam_masuk <= 0 || jam_masuk > 24 ){
throw new IllegalArgumentException();
}

lanjut=false;
}catch (InputMismatchException ex){
System.out.println("masukkan harus berupa angka");
input.nextLine();

}catch (IllegalArgumentException ex){


System.out.println("masukkan harus antara 1-24 jam");
}

}while(lanjut);
}

public int getjam_keluar() {


return jam_keluar;
}

public void setjam_keluar() {


do{
try {
System.out.print("Masukan Jam keluar : ");
jam_keluar = input.nextInt();

if(jam_keluar > 0){

}else
if(jam_keluar <= 0 || jam_keluar > 24 ){
throw new IllegalArgumentException();
}

lanjut=false;
}catch (InputMismatchException ex){
System.out.println("masukkan harus berupa angka");
input.nextLine();

}catch (IllegalArgumentException ex){


System.out.println("masukkan harus antara 1-24 jam");
}

}while(lanjut);

}
public int gettotal_Jam_Parkir(){
return total_Jam_Parkir = getjam_keluar()- getjam_masuk();
}
public int gettarif_parkir(){
return tarif_Parkir;
}

public void settarif_parkir(){


do{
try {

System.out.println("===============================");
System.out.println("1. motor");
System.out.println("2. mobil");
System.out.println("===============================");
System.out.println("+++++Masukan Kode Kendaraan+++++");
System.out.println("===============================");
int tipe = input.nextInt();

if(tipe == 1){
tarif_Parkir = gettotal_Jam_Parkir() * 2000;
System.out.println("Jenis Kendaraan : motor");

}else
if(tipe == 2 ){
tarif_Parkir = gettotal_Jam_Parkir() * 4000;
System.out.println("Jenis Kendaraan : Mobil");
}
if(tipe < 0 || tipe > 2 ){
throw new IllegalArgumentException();
}

lanjut=false;
}catch (InputMismatchException ex){
System.out.println("masukkan harus berupa angka");
input.nextLine();

}catch (IllegalArgumentException ex){


System.out.println("masukkan harus antara 1 & 2");
}
}while(lanjut);

public void tampil()throws IOException{


FileWriter file = new FileWriter("listDataParkir.txt", true);
BufferedWriter isi = new BufferedWriter(file);

System.out.println("===============================");
System.out.println("+++++Biaya Parkir+++++");
System.out.println("===============================");

System.out.println("No Polisi kendaraan: : "+No_polisi());


System.out.println("Jam Masuk : " + getjam_masuk()+ "WIB");
System.out.println("Jam Keluar : " + getjam_keluar()+ "WIB");
System.out.println("Lama Parkir : " + gettotal_Jam_Parkir() + "Jam");
System.out.println("Tarif Parkir : Rp." +gettarif_parkir() );

isi.write("=======================================\n" );
isi.write("========= Data parkir ==================\n" );
isi.write("=======================================\n\n" );
isi.write("No Polisi : "+No_Polisi+"\n");
isi.write("Jam msauk : "+jam_masuk+ " WIB \nJam keluar : " + jam_keluar+" WIB");
isi.write("\nLama parkir :"+total_Jam_Parkir+ " Jam \nTarif parkir :" + tarif_Parkir);
isi.newLine();
isi.flush();
}

public static void main(String[] args) throws IOException {

dataparkir2 x = new dataparkir2();


x.setNo_polisi();
x.setjam_masuk();
x.setjam_keluar();
x.settarif_parkir();
x.tampil();

}
}

* keseluruhan input akan di simpan dalam file berformat txt “ListDataParkir.txt”.


* juga untuk file asli kita lampirkan dibawah ini :

Tugas Besar PL(program perhitungan parkir).zip

You might also like