In: Computer Science
Write a program for XXX Phones, a provider of cellular phone service. Prompt a user for maximum monthly values for talk minutes used, text messages sent, and gigabytes of data used, and then recommend the best plan for the customer’s needs. A customer who needs fewer than 400 minutes of talk and no text or data should accept Plan A at $29 per month. A customer who needs fewer than 400 minutes of talk and any text messages should accept Plan B at $35 per month. A customer who needs 400 or more minutes of talk and no data should accept either Plan C for up to 100 text messages at $45 per month or Plan D for 100 text messages or more at $50 per month. A customer who needs any data should accept Plan E for up to 2 gigabytes at $59 or Plan F for 2 gigabytes or more at $65. Save the file as CellPhoneService.java
Again, Don’t forget to create the application/project CellPhoneServiceTest.java Class that has the main method and an object to use the CellPhoneService class.
import java.util.Scanner;
public class CellPhoneService {
private static final int PLAN_A = 29;
private static final int PLAN_B = 35;
private static final int PLAN_C = 45;
private static final int PLAN_D = 50;
private static final int PLAN_E = 59;
private static final int PLAN_F = 65;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char yesno;
do
{
System.out.print("Enter the maximum number of monthly call minutes
required: ");
int callMinutes = Integer.parseInt(sc.nextLine().trim());
System.out.print("Enter the maximum number of monthly text messages
required: ");
int textMessages = Integer.parseInt(sc.nextLine().trim());
System.out.print("Enter the maximum GB of data required: ");
int dataUsed = Integer.parseInt(sc.nextLine().trim());
suggestPlan(callMinutes, textMessages, dataUsed);
System.out.print("\nContinue? [y/n]: ");
yesno = sc.nextLine().trim().charAt(0);
if(yesno == 'N' || yesno == 'n')
break;
System.out.println();
}while(yesno != 'N' || yesno != 'n');
}
private static void suggestPlan(int call, int text, int data)
{
if(call < 400 && text == 0 && data == 0)
System.out.println("You can choose PLAN A at $" + PLAN_A);
else if(call < 400 && text > 0 && data ==
0)
System.out.println("You can choose PLAN B at $" + PLAN_B);
else if(call >= 400 && text <= 100 && data ==
0)
System.out.println("You can choose PLAN C at $" + PLAN_C);
else if(call >= 400 && text >= 100 && data ==
0)
System.out.println("You can choose PLAN D at $" + PLAN_D);
else if(call >= 400 && text > 0 && data <=
2)
System.out.println("You can choose PLAN E at $" + PLAN_E);
else if(call >= 400 && text > 0 && data >=
2)
System.out.println("You can choose PLAN F at $" + PLAN_F);
}
}
********************************************************* SCREENSHOT *******************************************************