InternetService.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class InternetService
{
public static void main(String[] args)
{
DecimalFormat df=new DecimalFormat(\"#.##\");
//initialize variable
char packageType;
int time;
double totalCharges;
double packA;
double packB;
double packC;
// create an object for Scanner class
Scanner input = new Scanner(System.in);
// prompt the user to enter the package purchased
System.out.print(\"\ Enter the package purchased: \");
packageType = input.next().charAt(0);
//prompt the user to enter the number of minutes used
System.out.print(\"Enter the number of minutes used: \");
time = input.nextInt();
//Calculate the bill amount of the particular month using the type of package and the number of
minutes.
//Then print results to the screen
switch(packageType)
{
case \'A\':
//Calling the Method for Package A charges
totalCharges=calPackA(time);
//Displaying the package A charges.
System.out.println(\"For Package A:\ The total charges for this month is $\" + totalCharges);
//Calling the Method for Package B charges
packB=calPackB(time);
//Calling the Method for Package C charges
packC=calPackC(time);
//If the package B is Less Than package A then display the difference amount
if(totalCharges>packB)
System.out.println(\"Amount of Money Package A customer would save, if he Purchased
Package B is:$\"+df.format(totalCharges-packB));
//If the package C is Less Than package A then display the difference amount
if(totalCharges>packC)
System.out.println(\"Amount of Money Package A customer would save, if he Purchased
Package C is:$\"+df.format(totalCharges-packC));
break;
case \'B\':
//Calling the Method for Package B charges
totalCharges=calPackB(time);
//Displaying the package B charges.
System.out.println(\"For Package B:\ The total charges for this month is $\"
+df.format(totalCharges));
//Calling the Method for Package C charges
packC=calPackC(time);
//If the package B is Less Than package A then display the difference amount
if(totalCharges>packC)
System.out.println(\"Amount of Money Package B customer would save, if he Purchased
Package C is:$\"+df.format(totalCharges-packC));
break;
case \'C\':
//Calling the Method for Package C charges
totalCharges=calPackC(time);
//Displaying the package C charges.
System.out.print(\"For Package C:\ The total charges for this month is $\" + totalCharges);
break;
default:
System.out.println(\"\ The package should be A or B or C.\");
}
}
/*This method will calculate the total Charges for Package C
* Params:Time
* Return:total charges of type double
*/
private static double calPackC(int time) {
double totalCharges = 69.99;
return totalCharges;
}
/*This method will calculate the total Charges for Package B
* Params:Time
* Return:total charges of type double
*/
private static double calPackB(int time) {
double totalCharges=0.0;
if(time <= 900)
totalCharges = 59.99;
else
totalCharges = 59.99 + (0.40 * (time - 900));
return totalCharges;
}
/*This method will c.
1. InternetService.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class InternetService
{
public static void main(String[] args)
{
DecimalFormat df=new DecimalFormat("#.##");
//initialize variable
char packageType;
int time;
double totalCharges;
double packA;
double packB;
double packC;
// create an object for Scanner class
Scanner input = new Scanner(System.in);
// prompt the user to enter the package purchased
System.out.print(" Enter the package purchased: ");
packageType = input.next().charAt(0);
//prompt the user to enter the number of minutes used
System.out.print("Enter the number of minutes used: ");
time = input.nextInt();
//Calculate the bill amount of the particular month using the type of package and the number of
minutes.
//Then print results to the screen
switch(packageType)
{
case 'A':
//Calling the Method for Package A charges
2. totalCharges=calPackA(time);
//Displaying the package A charges.
System.out.println("For Package A: The total charges for this month is $" + totalCharges);
//Calling the Method for Package B charges
packB=calPackB(time);
//Calling the Method for Package C charges
packC=calPackC(time);
//If the package B is Less Than package A then display the difference amount
if(totalCharges>packB)
System.out.println("Amount of Money Package A customer would save, if he Purchased
Package B is:$"+df.format(totalCharges-packB));
//If the package C is Less Than package A then display the difference amount
if(totalCharges>packC)
System.out.println("Amount of Money Package A customer would save, if he Purchased
Package C is:$"+df.format(totalCharges-packC));
break;
case 'B':
//Calling the Method for Package B charges
totalCharges=calPackB(time);
//Displaying the package B charges.
System.out.println("For Package B: The total charges for this month is $"
+df.format(totalCharges));
//Calling the Method for Package C charges
packC=calPackC(time);
//If the package B is Less Than package A then display the difference amount
if(totalCharges>packC)
System.out.println("Amount of Money Package B customer would save, if he Purchased
3. Package C is:$"+df.format(totalCharges-packC));
break;
case 'C':
//Calling the Method for Package C charges
totalCharges=calPackC(time);
//Displaying the package C charges.
System.out.print("For Package C: The total charges for this month is $" + totalCharges);
break;
default:
System.out.println(" The package should be A or B or C.");
}
}
/*This method will calculate the total Charges for Package C
* Params:Time
* Return:total charges of type double
*/
private static double calPackC(int time) {
double totalCharges = 69.99;
return totalCharges;
}
/*This method will calculate the total Charges for Package B
* Params:Time
* Return:total charges of type double
*/
private static double calPackB(int time) {
double totalCharges=0.0;
if(time <= 900)
4. totalCharges = 59.99;
else
totalCharges = 59.99 + (0.40 * (time - 900));
return totalCharges;
}
/*This method will calculate the total Charges for Package A
* Params:Time
* Return:total charges of type double
*/
private static double calPackA(int time) {
double totalCharges=0.0;
if(time <= 450)
totalCharges = 39.99;
else
totalCharges = 39.99 + (0.45 * (time - 450));
return totalCharges;
}
}
____________________________________________
Output1:
Enter the package purchased: A
Enter the number of minutes used: 440
For Package A:
The total charges for this month is $39.99
________________________________________________
output2:
Enter the package purchased: A
Enter the number of minutes used: 1000
For Package A:
The total charges for this month is $287.49
Amount of Money Package A customer would save, if he Purchased Package B is:$187.5
Amount of Money Package A customer would save, if he Purchased Package C is:$217.5
____________________________________________________
Output3:
Enter the package purchased: B
Enter the number of minutes used: 440
5. For Package B:
The total charges for this month is $59.99
____________________________________________________
Output4:
Enter the package purchased: B
Enter the number of minutes used: 1000
For Package B:
The total charges for this month is $99.99
Amount of Money Package B customer would save, if he Purchased Package C is:$30
____________________________________________
Solution
InternetService.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class InternetService
{
public static void main(String[] args)
{
DecimalFormat df=new DecimalFormat("#.##");
//initialize variable
char packageType;
int time;
double totalCharges;
double packA;
double packB;
double packC;
// create an object for Scanner class
Scanner input = new Scanner(System.in);
// prompt the user to enter the package purchased
System.out.print(" Enter the package purchased: ");
6. packageType = input.next().charAt(0);
//prompt the user to enter the number of minutes used
System.out.print("Enter the number of minutes used: ");
time = input.nextInt();
//Calculate the bill amount of the particular month using the type of package and the number of
minutes.
//Then print results to the screen
switch(packageType)
{
case 'A':
//Calling the Method for Package A charges
totalCharges=calPackA(time);
//Displaying the package A charges.
System.out.println("For Package A: The total charges for this month is $" + totalCharges);
//Calling the Method for Package B charges
packB=calPackB(time);
//Calling the Method for Package C charges
packC=calPackC(time);
//If the package B is Less Than package A then display the difference amount
if(totalCharges>packB)
System.out.println("Amount of Money Package A customer would save, if he Purchased
Package B is:$"+df.format(totalCharges-packB));
//If the package C is Less Than package A then display the difference amount
if(totalCharges>packC)
System.out.println("Amount of Money Package A customer would save, if he Purchased
Package C is:$"+df.format(totalCharges-packC));
break;
case 'B':
7. //Calling the Method for Package B charges
totalCharges=calPackB(time);
//Displaying the package B charges.
System.out.println("For Package B: The total charges for this month is $"
+df.format(totalCharges));
//Calling the Method for Package C charges
packC=calPackC(time);
//If the package B is Less Than package A then display the difference amount
if(totalCharges>packC)
System.out.println("Amount of Money Package B customer would save, if he Purchased
Package C is:$"+df.format(totalCharges-packC));
break;
case 'C':
//Calling the Method for Package C charges
totalCharges=calPackC(time);
//Displaying the package C charges.
System.out.print("For Package C: The total charges for this month is $" + totalCharges);
break;
default:
System.out.println(" The package should be A or B or C.");
}
}
/*This method will calculate the total Charges for Package C
* Params:Time
* Return:total charges of type double
*/
8. private static double calPackC(int time) {
double totalCharges = 69.99;
return totalCharges;
}
/*This method will calculate the total Charges for Package B
* Params:Time
* Return:total charges of type double
*/
private static double calPackB(int time) {
double totalCharges=0.0;
if(time <= 900)
totalCharges = 59.99;
else
totalCharges = 59.99 + (0.40 * (time - 900));
return totalCharges;
}
/*This method will calculate the total Charges for Package A
* Params:Time
* Return:total charges of type double
*/
private static double calPackA(int time) {
double totalCharges=0.0;
if(time <= 450)
totalCharges = 39.99;
else
totalCharges = 39.99 + (0.45 * (time - 450));
return totalCharges;
}
}
____________________________________________
Output1:
Enter the package purchased: A
Enter the number of minutes used: 440
For Package A:
9. The total charges for this month is $39.99
________________________________________________
output2:
Enter the package purchased: A
Enter the number of minutes used: 1000
For Package A:
The total charges for this month is $287.49
Amount of Money Package A customer would save, if he Purchased Package B is:$187.5
Amount of Money Package A customer would save, if he Purchased Package C is:$217.5
____________________________________________________
Output3:
Enter the package purchased: B
Enter the number of minutes used: 440
For Package B:
The total charges for this month is $59.99
____________________________________________________
Output4:
Enter the package purchased: B
Enter the number of minutes used: 1000
For Package B:
The total charges for this month is $99.99
Amount of Money Package B customer would save, if he Purchased Package C is:$30
____________________________________________