Answer to Question #162204 in Java | JSP | JSF for AJ

Question #162204

Create a java program that would compute and display the total mobile services fee incurred by a customer. Mobile services include text messages, calls in minutes and mobile data usage in megabytes.

Each customer was given a customer ID that would indicate the type of mobile plan he/she availed.

PLAN A:

-Customer ID ending with 0. Loyal member has 5 digits and above ID number.

-monthly fixed rate of P500.00

-allows free text messaging up to 250 messages. Beyond that, each message is charged 90 centavos.

-All-net calls up to 60 mins. Exceeding minutes applies P5/min.

-P5/MB. Free use of mobile data up to 80MB.

-20% discount from the total charge for Loyal member.

PLAN B:

-Customer ID ending with 5. Loyal member has 5 digits and above ID number.

-monthly fixed rate of P750.00

-allows free text messaging of up to 500 messages. Beyond that, each message is charged 70 centavos.

-All-net calls up to 120 mins. Exceeding minutes applies P5/min.

-P5/MB. Free use of mobile data up to 100MB.

-40% discount from the total charge.

PLAN C:

-Customer ID ending with 2. Loyal member has 5 digits and above ID number.

-monthly fixed rate of P1,200.00

-allows free text messaging of up to 1,000 messages. Beyond that, each message is charged 50 centavos.

-All-net calls up to 240 mins. Exceeding minutes applies P5/min.

-P5/MB. Free use of mobile data up to 500MB.

-60% discount from the total charge.


Input:

The first line of the input file will contain a single integer N that represents the

Customer ID number. Next line consists of 3 integer T, C and D, separated by commas (,). T is the total number of text messages; C is the total number of calls in minutes and D is the total data usage in MB.


Output:

The total mobile fee of the customer applying all charges given in the description and discounts if applicable. In addition, the program must also display an offer to upgrade the plan type for customers who have exceeded their monthly fixed rate by 200%.

Ex. Plan A

–Total bill of P1,860.00 means the customer exceeded by P1,360.00 or 272% from his/her monthly fixed rate of P500 (P1,860-500=1,360).






1
Expert's answer
2021-02-09T15:27:13-0500
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Main {

    public static void main(String[] args) {
        try {
            BufferedReader in = new BufferedReader(new FileReader("input.txt"));
            String id = in.readLine();
            int messages = Integer.parseInt(in.readLine());
            int calls = Integer.parseInt(in.readLine());
            int data = Integer.parseInt(in.readLine());
            double[] fixedRates = {500, 750, 1200};
            int[] mLimit = {250, 500, 1000};
            double[] mCharge = {0.9, 0.7, 0.5};
            int[] cLimit = {60, 120, 240};
            int[] dLimit = {80, 100, 500};
            double[] discount = {0.8, 0.6, 0.4};
            double total = 0;
            int i;
            switch (id.charAt(id.length() - 1)) {
                case '0':
                    i = 0;
                    break;
                case '5':
                    i = 1;
                    break;
                case '2':
                    i = 2;
                    break;
                default:
                    System.out.println("Unknown id");
                    return;
            }
            total += fixedRates[i];
            if (messages > mLimit[i]) {
                total += mCharge[i] * (messages - mLimit[i]);
            }
            if (calls > cLimit[i]) {
                total += 5 * (calls - cLimit[i]);
            }
            if (data > dLimit[i]) {
                total += 5 * (data - dLimit[i]);
            }
            if (i == 0) {
                if (id.length() >= 5) {
                    total *= discount[i];
                }
            } else {
                total *= discount[i];
            }
            if ((total - fixedRates[i]) / fixedRates[i] > 2) {
                System.out.println("We suggest updating the plan.");
            }
            System.out.println("TOTAL " + id + ": P " + total);
        } catch (IOException e) {
        }
    }
}

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