Answer to Question #278608 in Java | JSP | JSF for Lulu

Question #278608

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.

  1. Any call made after 6.00 a.m. to 6.00 p.m. is charged Kshs 4.00 per minute.
  2. Any call made after 6.00 p.m. to 6.00 a.m. is charged Kshs 3.00 per minute.
  3. Any call to another network is charged Kshs 5.00 irrespective of the time.
  4. In addition to the above charges one also pays 16% Vat for calls taking longer than two minutes.

Required

Write an object oriented Java program that can be used by the company to bill its customers.



1
Expert's answer
2021-12-12T01:17:30-0500
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;

    }

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS