JAVA
Modify the program you wrote for Programming Challenge 13 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.
My Code:
import java.util.Scanner;
public class MobilePackage {
final static double COSTPACKA = 39.99;
final static double COSTPACKB = 59.99;
final static double COSTPACKC = 69.99;
final static double ADDITIONALCOSTA = 0.45;
final static double ADDITIONALCOSTB = 0.40;
final static double MINUTESPACKA = 450;
final static double MINUTESPACKB = 900;
public static void main(String[] args) {
double minused = 0, billA, billB;
String choice;
Scanner sc = new Scanner(System.in);
do {
System.out.println("Select a subscription package: ");
System.out.println("A: Package A");
System.out.println("B: Package B");
System.out.println("C: Package C");
System.out.println("Q: Quit");
System.out.print("Enter package: ");
choice = sc.next();
switch (choice) {
case "A":
System.out.print("How many minutes were used during the month: ");
minused = sc.nextDouble();
if (minused <= MINUTESPACKA) {
System.out.println("Total cost is: " + COSTPACKA);
// saving with package B
System.out.println("No savings with package B");
// saving with package C
System.out.println("No savings with package C");
} else {
billA = ((minused - MINUTESPACKA) * ADDITIONALCOSTA) + COSTPACKA;
billB = (minused - MINUTESPACKB) * ADDITIONALCOSTB + COSTPACKB;
System.out.println("Total cost is: " + billA + "$");
// saving with package B
if (minused <= MINUTESPACKB && billA > COSTPACKB) {
System.out.println("Savings with package B: " + (billA - COSTPACKB) + "$");
} else if (minused > MINUTESPACKB && billA > billB) {
System.out.println("Savings with package B: " + (billA - billB) + "$");
} else {
System.out.println("No savings with package B");
}
// saving with package C
if (billA > COSTPACKC) {
System.out.println("Savings with package C: " + (billA - COSTPACKC) + "$");
} else {
System.out.println("No savings with package C");
}
}
System.out.println();
break;
case "B":
System.out.print("How many minutes were used during the month: ");
minused = sc.nextDouble();
if (minused <= MINUTESPACKB) {
billA = ((minused - MINUTESPACKA) * ADDITIONALCOSTA) + COSTPACKA;
System.out.println("Total cost is:" + COSTPACKB);
// saving with package A
if (minused <= MINUTESPACKA) {
System.out.println("Savings with package A: " + (COSTPACKB - COSTPACKA) + "$");
} else if (minused > MINUTESPACKA && billA < COSTPACKB) {
System.out.println("Savings with package A: " + (COSTPACKB - billA) + "$");
} else {
System.out.println("No savings with package A");
}
// saving with package C
System.out.println("No savings with package C");
} else {
billB = (minused - MINUTESPACKB) * ADDITIONALCOSTB + COSTPACKB;
System.out.println("Total cost is: " + billB + "$");
// saving with package A
System.out.println("No savings with package A");
// saving with package C
if (billB > COSTPACKC) {
System.out.println("Savings with package C: " + (billB - COSTPACKC) + "$");
} else {
System.out.println("No savings with package C");
}
}
System.out.println();
break;
case "C":
System.out.print("How many minutes were used during the month: ");
minused = sc.nextDouble();
if (minused <= MINUTESPACKB) {
billA = ((minused - MINUTESPACKA) * ADDITIONALCOSTA) + COSTPACKA;
billB = (minused - MINUTESPACKB) * ADDITIONALCOSTB + COSTPACKB;
System.out.println("Total cost is:" + COSTPACKC);
// saving with package A
if (minused <= MINUTESPACKA) {
System.out.println("Savings with package A: " + (COSTPACKC - COSTPACKA) + "$");
} else if (minused > MINUTESPACKA && billA < COSTPACKC) {
System.out.println("Savings with package A: " + (COSTPACKC - billA) + "$");
} else {
System.out.println("No savings with package A");
}
// saving with package C
if (minused <= MINUTESPACKB) {
System.out.println("Savings with package C: " + (COSTPACKC - COSTPACKB) + "$");
} else if (minused > MINUTESPACKB && billB < COSTPACKC) {
System.out.println("Savings with package C: " + (COSTPACKC - billB) + "$");
} else {
System.out.println("No savings with package C");
}
} else {
System.out.println("Total cost is: " + COSTPACKC + "$");
// saving with package A
System.out.println("No savings with package A");
// saving with package B
System.out.println("No savings with package B");
}
System.out.println();
break;
case "Q":
System.out.print("Thank you!");
break;
default:
System.out.println("Invalid Choice");
System.out.println();
}
} while (!choice.equals("Q"));
sc.close();
}
}

JAVA Modify the program you wrote for Programming Challenge 13 so it.pdf

  • 1.
    JAVA Modify the programyou wrote for Programming Challenge 13 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. My Code: import java.util.Scanner; public class MobilePackage { final static double COSTPACKA = 39.99; final static double COSTPACKB = 59.99; final static double COSTPACKC = 69.99; final static double ADDITIONALCOSTA = 0.45; final static double ADDITIONALCOSTB = 0.40; final static double MINUTESPACKA = 450; final static double MINUTESPACKB = 900; public static void main(String[] args) { double minused = 0, billA, billB; String choice; Scanner sc = new Scanner(System.in); do { System.out.println("Select a subscription package: "); System.out.println("A: Package A"); System.out.println("B: Package B"); System.out.println("C: Package C"); System.out.println("Q: Quit");
  • 2.
    System.out.print("Enter package: "); choice= sc.next(); switch (choice) { case "A": System.out.print("How many minutes were used during the month: "); minused = sc.nextDouble(); if (minused <= MINUTESPACKA) { System.out.println("Total cost is: " + COSTPACKA); // saving with package B System.out.println("No savings with package B"); // saving with package C System.out.println("No savings with package C"); } else { billA = ((minused - MINUTESPACKA) * ADDITIONALCOSTA) + COSTPACKA; billB = (minused - MINUTESPACKB) * ADDITIONALCOSTB + COSTPACKB; System.out.println("Total cost is: " + billA + "$"); // saving with package B if (minused <= MINUTESPACKB && billA > COSTPACKB) { System.out.println("Savings with package B: " + (billA - COSTPACKB) + "$"); } else if (minused > MINUTESPACKB && billA > billB) { System.out.println("Savings with package B: " + (billA - billB) + "$"); } else { System.out.println("No savings with package B");
  • 3.
    } // saving withpackage C if (billA > COSTPACKC) { System.out.println("Savings with package C: " + (billA - COSTPACKC) + "$"); } else { System.out.println("No savings with package C"); } } System.out.println(); break; case "B": System.out.print("How many minutes were used during the month: "); minused = sc.nextDouble(); if (minused <= MINUTESPACKB) { billA = ((minused - MINUTESPACKA) * ADDITIONALCOSTA) + COSTPACKA; System.out.println("Total cost is:" + COSTPACKB); // saving with package A if (minused <= MINUTESPACKA) { System.out.println("Savings with package A: " + (COSTPACKB - COSTPACKA) + "$"); } else if (minused > MINUTESPACKA && billA < COSTPACKB) { System.out.println("Savings with package A: " + (COSTPACKB - billA) + "$"); } else { System.out.println("No savings with package A");
  • 4.
    } // saving withpackage C System.out.println("No savings with package C"); } else { billB = (minused - MINUTESPACKB) * ADDITIONALCOSTB + COSTPACKB; System.out.println("Total cost is: " + billB + "$"); // saving with package A System.out.println("No savings with package A"); // saving with package C if (billB > COSTPACKC) { System.out.println("Savings with package C: " + (billB - COSTPACKC) + "$"); } else { System.out.println("No savings with package C"); } } System.out.println(); break; case "C": System.out.print("How many minutes were used during the month: "); minused = sc.nextDouble(); if (minused <= MINUTESPACKB) { billA = ((minused - MINUTESPACKA) * ADDITIONALCOSTA) + COSTPACKA; billB = (minused - MINUTESPACKB) * ADDITIONALCOSTB + COSTPACKB;
  • 5.
    System.out.println("Total cost is:"+ COSTPACKC); // saving with package A if (minused <= MINUTESPACKA) { System.out.println("Savings with package A: " + (COSTPACKC - COSTPACKA) + "$"); } else if (minused > MINUTESPACKA && billA < COSTPACKC) { System.out.println("Savings with package A: " + (COSTPACKC - billA) + "$"); } else { System.out.println("No savings with package A"); } // saving with package C if (minused <= MINUTESPACKB) { System.out.println("Savings with package C: " + (COSTPACKC - COSTPACKB) + "$"); } else if (minused > MINUTESPACKB && billB < COSTPACKC) { System.out.println("Savings with package C: " + (COSTPACKC - billB) + "$"); } else { System.out.println("No savings with package C"); } } else { System.out.println("Total cost is: " + COSTPACKC + "$"); // saving with package A System.out.println("No savings with package A"); // saving with package B System.out.println("No savings with package B");
  • 6.
    } System.out.println(); break; case "Q": System.out.print("Thank you!"); break; default: System.out.println("InvalidChoice"); System.out.println(); } } while (!choice.equals("Q")); sc.close(); } }