Question

write in java and you must use methods.... Part I     Internet Service Provider An Internet service...

write in java and you must use methods....

Part I     Internet Service Provider

An Internet service provider has three different subscription packages for its customers:

Package A: For $9.95 per month 10 hours of access are provided. Additional hours

are $2.00 per hour.

Package B: For $13.95 per month 20 hours of access are provided. Additional hours

are $1.00 per hour.

Package C: For $19.95 per month unlimited access is provided.

Write a program that calculates a customer’s monthly bill. It should ask the user to enter

the letter of the package the customer has purchased (A, B, or C) and the number of hours

that were used. It should then display the total charges.

Part 2   Internet Service Provider

Modify the program you wrote for Programming in part 1 so it also calculates and

displays the amount of money Package A customers would save if they purchased Package

B or C, and the amount of money Package B customers would save if they purchased Package If there would be no savings, no message should be printed.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the complete code as per the requirements. It is well explained inside the code using comments.


import java.util.Scanner;

// InternetServiceProvider class
public class InternetServiceProvider {

    // main method
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);     // to read the input
        char pack;                                  // to store letter of package
        int hours;                                  // to store number of hours
        double totalCharges;                        // to store total charges
        double savings;                             // to store savings

        // display package details
        displayPackage();

        // read package letter and nunber of hours
        System.out.print("Enter the letter of package [A/B/C]: ");
        pack = input.nextLine().charAt(0);
        System.out.print("Enter the number of hours: ");
        hours = input.nextInt();

        // call method to calculate total charges
        totalCharges = getTotalCharges(pack, hours);

        // display the total charges
        System.out.println("Total charges: $" + totalCharges);

        // check for savings, display message if any
        if (pack == 'A') {
            if (totalCharges > 13.95) {
                savings = totalCharges - 13.95;
                System.out.println("If you purchase package B, you would save $" + savings);
            }
            else if (totalCharges > 19.95) {
                savings = totalCharges - 19.95;
                System.out.println("If you purchase package C, you would save $" + savings);
            }
        }
        else if (pack == 'B') {
            if (totalCharges > 19.95) {
                savings = totalCharges - 19.95;
                System.out.println("If you purchase package C, you would save $" + savings);
            }
        }
    }

    // displays package details
    private static void displayPackage() {
        System.out.println("Package A: For $9.95 per month - 10 hours of access. Additional hours are $2.00 per hour.");
        System.out.println("Package B: For $13.95 per month - 20 hours of access. Additional hours are $1.00 per hour.");
        System.out.println("Package C: For $19.95 per month - unlimited access");
    }

    // calculates and return the total charges
    private static double getTotalCharges(char pack, int hours) {
        double total = 0;
        int extraHours = 0;

        // calculate total charges on the basis of pack and hours
        switch (pack) {
            case 'A':
                if (hours > 10) {
                    extraHours = hours - 10;
                }
                total = 9.95 + (2 * extraHours);
                break;
            case 'B':
                if (hours > 20) {
                    extraHours = hours - 20;
                }
                total = 13.95 + extraHours;
                break;
            case 'C':
                total = 19.95;
                break;
            default:
                System.out.println("Invalid Package.");
        }
        return total;
    }
}

Below are the sample outputs:

This completes the requirement. Let me know if you have any queries.

Thanks!

Add a comment
Know the answer?
Add Answer to:
write in java and you must use methods.... Part I     Internet Service Provider An Internet service...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Internet Service Provider

    Package A = $9.95 per month 10 hrs access provided. Additional hrs are $2 per hour.Package B= $13.95 per month 20 hrs access provided. Additional hrs are $1 per hour.Package C = $19.95 per month unlimited access provided.Write a program that calculates a customer's monthly bill to display the letter of the packaged purchased and the number of hours used. Finally display the totalcharges.

  • An Internet service provider has three different subscription packages for its customers: Package A: For $15...

    An Internet service provider has three different subscription packages for its customers: Package A: For $15 per month with 50 hours of access provided. Additional hours are $2.00 per hour over 50 hours. Assume usage is recorded in one-hour increments. Package B: For $20 per month with 100 hours of access provided. Additional hours are $1.50 per hour over 100 hours. Package C: For $25 per month with 150 hours access is provided.    Additional hours are $1.00 per hour...

  • Part 1: A mobile phone service provider has three different data plans for its customers: Package...

    Part 1: A mobile phone service provider has three different data plans for its customers: Package A: For $39.99 per month 4 gigabytes are provided. Additional data costs $10 per gigabyte. Package B: For $59.99 per month, 8 gigabytes are provided. Additional data costs $5 per gigabyte. Package C: For $69.99 per month, unlimited data is provided. Write a program that calculates a customer's monthly bill. It should ask which package the customer has purchased and how many gigabytes were...

  • An Internet service provider offers four subscription packages to its customers, plus a discount for nonprofit...

    An Internet service provider offers four subscription packages to its customers, plus a discount for nonprofit organizations: Package A: 10 hours of access for $12.95 per month. Additional hours are $4.00 per hour. Package B: 20 hours of access for $14.95 per month. Additional hours are $2.00 per hour. Package C: 30 hours of access for $20 per month. Additional hours are $1.00 per hour. Package D: Unlimited access for $35.95 per month. A nonprofit organizations will get 20% discount...

  • write in C++ Problem 1: Mobile Service Provider A cell phone service provider has three different...

    write in C++ Problem 1: Mobile Service Provider A cell phone service provider has three different subscription packages for its customers. Package A: For $39.99 per month 450 minutes are provided. Additional minutes are $0.45 per minute. Package B: For $59.99 per month 900 minutes are provided. Additional minutes are $0.40 per minute. Package C: For $69.99 per month unlimited minutes provided. Write a program that calculates a customer’s monthly bill. It should ask which package the customer has purchased...

  • Problem: Mobile Service Provider A mobile service provider has three different subscription packages for its customers:...

    Problem: Mobile Service Provider A mobile service provider has three different subscription packages for its customers: • Package A: For $50 per month, 5 GB data are provided. Additional data is $15 per GB. • Package B: For $65 per month, 10 data are provided. Additional data is $10 per GB. • Package C: For $75 per month unlimited data provided. Text messaging and voice services are included in all of the company's data packages. The Mobile Service Company offers...

  • Modify the program below so it also calculates and displays the amount of money Package A...

    Modify the program below so it also calculates and displays the amount of money Package A customers would save if they purchased Package B or C, and the amount of money Package B customers would save if they purchased Package C. If there would be no savings, no message should be printed. import java.util.*; public class Lab2 { public static void main (String[] args) {    //scanner Scanner input = new Scanner(System.in);    //declarations int hours; char pack; double totalCharges...

  • Java Programming Problem description with its major requirements labeled from A to I. A mobile phone...

    Java Programming Problem description with its major requirements labeled from A to I. A mobile phone service provider has three different subscription packages for its customers: Package A: For $39.99 per month 450 minutes are provided. Additional minutes are $0.45 per minute. Package B: For $59.99 per month 900 minutes are provided. Additional minutes are $0.40 per minute. Package C: For $69.99 per month unlimited minutes are provided. Design a class MobileCharges that calculates a customer’s monthly bill. It should...

  • Please can someone help me with making this program in JAVA implementing classes. Also, include loops...

    Please can someone help me with making this program in JAVA implementing classes. Also, include loops and selection structures. A mobile service provider has three different subscription packages for its customers: Package A: For $50 per month, 5 GB data are provided. Additional data is $15 per GB. Package B: For $65 per month, 10 data are provided. Additional data is $10 per GB. Package C: For $75 per month unlimited data provided. Text messaging and voice services are included...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT