This is a Java program
Program Description
You work for a local cell phone company and have been asked to write a program to calculate the price of a cell phone data plan being purchased by a customer.
The program should do the following tasks:
The program should include the following methods:
Data Plan Size |
Base Price |
1 GB |
$34.99 |
2 GB |
$49.99 |
4 GB |
$64.99 |
Unlimited |
$74.99 Unlimited plans include two (2) free lines |
Cell Phone Plan Cost = BASE PRICE + (10.00 * NUMBER OF PHONE LINES)
Note: Unlimited plans include two (2) free lines. For example, an unlimited plan with 6 phone lines would have its cost calculated as follows:
Cell Phone Plan Cost = $74.99 + ($10.00 * (6-2)) = $114.99
All methods should be coded as instructed above. Modifying the methods (adding or removing parameters, changing return type, etc…) will count as a major error (i.e., one major error deduction for each method that is modified.)
You should call the methods you created above from the main method.
The output of the program (including spacing and formatting) should match the Sample Input and Output shown below.
Sample Input and Output (include spacing as shown below). Do not modify the input and output statements.
Data Plan Menu:
1. 1 GB
2. 2 GB
3. 4 GB
4. Unlimited
Select a plan from the menu above: 4
Enter the number of phones: 5
The total price of the cell phone plan (before tax and fees) is:
$104.99
Do you wish to calculate the price of another plan (Y/N)?Y
Data Plan Menu:
1. 1 GB
2. 2 GB
3. 4 GB
4. Unlimited
Select a plan from the menu above: 2
Enter the number of phones: 1
The total price of the cell phone plan (before tax and fees) is:
$59.99
Do you wish to calculate the price of another plan (Y/N)?N
Code
import java.util.Scanner;
public class Main {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
char again;
int selectedPlan;
double cost;
do
{
menu();
do
{
System.out.print("Select a plan from the menu above:");
selectedPlan=sc.nextInt();
if(selectedPlan<0 || selectedPlan>4)
System.out.println("Please etner valid plan.");
}while(selectedPlan<0 || selectedPlan>4);
cost=calculateCost(selectedPlan);
System.out.println("The total price of the cell phone plan (before
tax and fees) is: $"+cost);
System.out.print("Do you wish to calculate the price of another
plan (Y/N)?");
again=sc.next().charAt(0);
}while(again=='Y'||again=='y');
}
public static void menu() {
System.out.println("Data Plan Menu:\n1. 1 GB\n" +
"2. 2 GB\n" +
"3. 4 GB\n" +
"4. Unlimited");
}
private static double calculateCost(int plan)
{
int numLines;
do
{
System.out.print("Enter the number of phones:");
numLines=sc.nextInt();
if(numLines<0)
System.out.println("Please enter valid input.");
}while(numLines<0);
double totalCost=0;
switch(plan)
{
case 1:
totalCost=34.99+(10*numLines);
break;
case 2:
totalCost=49.99+(10*numLines);
break;
case 3:
totalCost=64.99+(10*numLines);
break;
case 4:
if(numLines>2)
totalCost=74.99+(10*(numLines-2));
else
totalCost=74.99;
break;
}
return totalCost;
}
}
output
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.
Get Answers For Free
Most questions answered within 1 hours.