Answer to Question #291637 in Java | JSP | JSF for kevin

Question #291637

Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of service: regular and premium. Rates vary based on the type of service and are computed as follows: Regular service: $10.00 plus the first 50 minutes are free. Charges for over 50 minutes are $0.20 per minute. Premium service: $25.00 plus: a. For calls made from 6:00 a.m. to 6:00 p.m., the first 75 minutes are free; charges for over 75 minutes are $0.10 per minute. b. For calls made from 6:00 p.m. to 6:00 a.m., the first 100 minutes are free; charges for over 100 minutes are $0.05 per minute. Your program should prompt the user to enter an account number, a service code (type char), and the number of minutes the service was used. A service code of r or R means regular service; a service code of p or P means premium service. Treat any other character as an error. Your program should output the account number, type of service, number of minutes the telephone


1
Expert's answer
2022-01-28T10:33:15-0500
import java.util.Scanner;

public class Main {

    public static double regularCost(int minutes) {
        double total = 10;
        if (minutes > 50) {
            total += (minutes - 50) * 0.2;
        }
        return total;
    }

    public static double premiumCost(int minutesAMToPM, int minutesPMToAM) {
        double total = 25;
        if (minutesAMToPM > 75) {
            total += (minutesAMToPM - 75) * 0.1;
        }
        if (minutesPMToAM > 100) {
            total += (minutesPMToAM - 100) * 0.05;
        }
        return total;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Account number:");
        String accountNumber = in.next();
        System.out.println("Service code( R | P ):");
        String serviceCode = in.next();
        if (serviceCode.length() == 1 &&
                (serviceCode.equalsIgnoreCase("R") || serviceCode.equalsIgnoreCase("P"))) {
            System.out.println("Number of minutes:");
            int minutes = in.nextInt();
            System.out.println("Account number: " + accountNumber
                    + "\nType of service: " + (serviceCode.equalsIgnoreCase("R") ? "Regular" : "Premium")
                    + "\nNumber of minutes: " + minutes);
        } else {
            System.out.println("Error");
        }
    }
}

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