2, Internet Service Provider.. An internet service provider has three different
ID: 3540400 • Letter: 2
Question
2, Internet Service Provider..
An internet service provider has three different subscription package 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 acustomer's monthly bill. It should ask the user to enter the letter of the package the customer has purchased (A,B,C) and the number of hours that were used.It should then display the total charges.
Complete Programming Challenge ( use netbeans) #13 Internet Service Provider on p. 215.
Include comments at the top of the file that gives your name and date and a brief description of the program%u2019s purpose. Include comments in the body of the code that describes what the code is doing. Be sure to use white space and indentation to make your program easy to understand.
You will need to accept package input as a String, then use charAt(0) to get the first letter. Consider how to handle input if user enters package a, rather than package A, etc.
Use the switch statement based on the package type to calculate the monthly bill, for example:
switch (package)
{
case %u2018A%u2019: // $9.95/month plus $2/hour over 10 hours
%u2026
Default: // display error message if not A, B, or C
} //end switch (package)
Explanation / Answer
import java.util.*;
public class InternetServiceProvider
{
public static void main(String[] args)
{
int hours;
char ch;
Scanner in = new Scanner(System.in);
System.out.println("Enter your package name (A,B,C) ");
ch = in.next().charAt(0);
System.out.println("Enter Number of hours worked");
hours = in.nextInt();
double total_charge =0;
switch(ch)
{
case 'A':
{
if(hours<10)
total_charge=9.95;
else
total_charge=9.95+((hours-10)*2.0);
}
break;
case 'B':
{
if(hours<20)
total_charge=14.95;
else
total_charge=14.95+((hours-20)*1);
}
break;
case 'C':
total_charge=19.95;
break;
default: System.out.println("Not a valid package");
}
System.out.println("Monthly bill on Package " + ch + " is: $" +total_charge);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.