public class lab01_task05 {
public static void main(String[] args) {
String[] arrivalDate = args[1].split("h");
String[] departureDate = args[2].split("h");
int hoursArrival = Integer.parseInt(arrivalDate[0]);
int minutesArrival = Integer.parseInt(arrivalDate[1]);
int hoursDeparture = Integer.parseInt(departureDate[0]);
int minutesDeparture = Integer.parseInt(departureDate[1]);
if (minutesDeparture < minutesArrival) {
hoursDeparture--;
minutesDeparture += 60;
}
int diffMinutes = minutesDeparture - minutesArrival;
int diffHours = hoursDeparture - hoursArrival;
int totalMinutes = diffMinutes + diffHours * 60;
// Duration Cost
float totalCost = 0;
// 0 to 30 minutes N$ 0
if (totalMinutes > 0 && totalMinutes < 30) {
totalCost=0;
}
// 0.5h to 8 hours N$ 2.50 per 30 minutes
if (totalMinutes >= 30 && totalMinutes < 480) {
totalCost=totalMinutes*2.5f/30.0f;
}
// Above 8 hours N$ 80.00
if (totalMinutes>= 480) {
totalCost=80.00f;
}
System.out.println("Vehicle Details");
System.out.println(args[0]);
System.out.println("++++++++++++++++++++++");
System.out.println("Arrival " + args[1]);
System.out.println("Departure " + args[2]);
System.out.println("++++++++++++++++++++++");
System.out.println("Total Cost: N$ " + String.format("%.2f", totalCost));
System.out.println("++++++++++++++++++++++");
}
}
Comments
Leave a comment