A certain mobile phone company charges its customers using per second billing. The tariff used is post paid. The following rules are used in the billing procedure.
Required
Write an object oriented Java program that can be used by the company to bill its customers.
import java.time.Duration;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class Main {
public double calculateCost(LocalTime start, LocalTime end, boolean inner) {
LocalTime sixAM = LocalTime.parse("06:00 AM", DateTimeFormatter.ofPattern("hh:mm a"));
LocalTime sixPM = LocalTime.parse("06:00 PM", DateTimeFormatter.ofPattern("hh:mm a"));
double duration = Math.abs(Duration.between(start, end).getSeconds() / 60.);
double rate;
if (inner) {
if (start.compareTo(sixAM) > 0 && start.compareTo(sixPM) <= 0) {
rate = 4;
} else {
rate = 3;
}
} else {
rate = 5;
}
return duration > 2 ? duration * rate * 1.16 : duration * rate;
}
}
Comments
Leave a comment