Question

This is a Java program Program Description You work for a local cell phone company and...

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:

  • Display a menu of the data plans that are available to be purchased.
  • Read in the user’s selection from the menu.  Input Validation: If the user enters an invalid option, the program should display an error message and ask them to re-enter their selection.
  • Ask the user to enter the number of phone lines on the plan. Input Validation: If the user enters a number of 0 or less, the program should display an error message and ask them to re-enter the number.
  • Output the cost of the cell phone plan.
  • Ask the user whether he/she wants to run the program again. If so, the steps above are repeated. If not, the program should terminate.

The program should include the following methods:

  1. A method that displays a data plan menu. This method should accept no arguments and should not return a value. See the Sample Input and Output for how to format the menu.
  2. A method that accepts one argument: the menu selection that indicates which data plan was selected. The method should return the base price using the information in the table below:

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

  1. A method that calculates the cost of a cell phone plan. This method should accept two arguments: the number of phone lines and the base price of the plan. The method should return the cost of the cell phone plan. The cost of the cell phone plan can be calculated as follows:

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

  1. A method that displays the final cost. The method should accept one argument: the final cost.

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

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Program Description A local company has requested a program to calculate the cost of different hot...
Program Description A local company has requested a program to calculate the cost of different hot tubs that it sells. Use the following instructions to code the program: File 1 - HotTubLastname.java Write a class that will hold fields for the following: The model of the hot tub The hot tub’s feature package (can be Basic or Premium) The hot tub’s length (in inches) The hot tub’s width (in inches) The hot tub’s depth (in inches) The class should also...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
Please program in JAVA: Program each option such as delete line and such. Your program will...
Please program in JAVA: Program each option such as delete line and such. Your program will be a line editor. A line editor is an editor where all operations are performed by entering commands at the command line. Commands include displaying lines, inserting text, editing lines, cutting and pasting text, loading and saving files. For example, a session where the user enters three lines of text and saves them as a new file may appear as: Menu: m Delete line:...
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers....
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers. The data for this program will be entered from the keyboard using JOptionPane one 16-bit binary number at a time. Note that each base 2 number is actually read in as a String. The program should continue until a 16-bit base 2 number consisting of all 0’s is entered. Once the 16-bit number has been entered your program should make sure that the input...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day...
Write a program in Java that: 1. will prompt user with a menu that contains options...
Write a program in Java that: 1. will prompt user with a menu that contains options to: a. Add a To-Do Item to a todo list. A To-Do Item contains: i. An arbitrary reference number (4; 44,004; etc.) ii. A text description of the item ("Pick up dry cleaning", etc.) iii. A priority level (1, 2, 3, 4, or 5) b. View an item in the list (based on its reference number) c. Delete an item from the list (based...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with four items. The user should then be prompted to make a selection from the menu and based on their selection the program will perform the selected procedure. The title and menu should be as the following: Student name: <your name should be printed> CIS 232 Introduction to Programming Programming Project 6 Due Date: October 23, 2020 Instructor: Dr. Lomako ******************************** 1.     Compute Angles                               *...
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2....
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2. Calculate Current in Amps 3. Calculate Voltage in volts 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for voltage in Volts and the current in Amps. Use the following formula: R= E/i Where: E= voltage in volts I= current in amps R= resistance in ohms If the user enters 2 the program should ask for the voltage...
a. The Talk-A-Lot Cell Phone Company provides phone services for its customers. Create an abstract class...
a. The Talk-A-Lot Cell Phone Company provides phone services for its customers. Create an abstract class named PhoneCall that includes a String field for a phone number and a double field for the price of the call. Also include a constructor that requires a phone number parameter and that sets the price to 0.0. Include a set method for the price. Also include three abstract get methods - one that returns the phone number, another that returns the price of...