Вы находитесь на странице: 1из 3

import java.io.

*;
class parking
{
public static void main(String[] args) throws IOException
{
char type;
int hourin, minutin, hourout, minutout;
hourin = 0;
minutin = 0;
hourout = 0;
minutout = 0;
double charge;
Pembaca read = new Pembaca();
System.out.println("Type of Vehicle? C - Car, B - Bus, T - Truck");
type = read.bacaChar();
System.out.println("Hour vehicle entered lot (0-24)? ");
hourin = read.bacaInt();
System.out.println("Minute vehicle entered lot (0-59)?");
minutin = read.bacaInt();
System.out.println("Hour vehicle left lot (0-23)? ");
hourout = read.bacaInt();
System.out.println("Minute vehicle left lot (0-60)?");
minutout = read.bacaInt();
int round = getTime();
switch (type){
case 'c': getCar(); break;
case 't': getTruck(); break;
case 'b': getBus(); break;
}
System.out.println("PARKING LOT CHARGE");
System.out.println("");
System.out.println("Type of vehicle: Car or Bus or Truck"+ type) ;
System.out.println("TIME-IN "+hourin+":" + minutin);
System.out.println("TIME-OUT "+hourout+":"+ minutout);
System.out.println(" --------------------------
--------");
System.out.println("PARKING TIME " + timeh + ":"
+ timem);
System.out.println("ROUNDED TOTAL : " +round);
System.out.println(" -------------------------
---------");
System.out.println(" -------------------------
---------");
System.out.println("TOTAL CHARGE RM" +charge);
}
public int getTime(){
int hourin, minutin, hourout, minutout;
hourin = 0;
minutin = 0;
hourout = 0;
minutout = 0;
int timeh = 0;
int timem = 0;
int round;
if (minutin < minutout){
minutout = minutout + 60;
hourout = hourout - 1;
}
else{
timeh = hourout - hourin;
timem = minutout - minutin;
}
if(timem > 30){
timem = 0;
timeh = timeh + 1;
round = timeh;
}
else{
timem = 0;
timeh = timeh;
round = timeh;
}
return round;
}
public double getCar(){
if(round >= 3)
{
charge = 1.5 * (round - 3);
System.out.println("parking charge = "+charge);
}
else
{
charge = 0;
System.out.println("parking charge = "+charge);
}
}
public double getTruck(){
if(round>2){
charge = 2.3 * (round - 2);
}
else
charge = 1;
}
public double getBus(){
if(round>2){
charge = 3.7 * (round - 2);
}
else
charge = 2;
}
}

Вам также может понравиться