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...
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...
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...
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                               *...
(8 marks) Write a program to ask user to input an integer and display the special...
Write a program to ask user to input an integer and display the special pattern accordingly. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use loop statements (for, while or do-while). Your program should use only the following 3 output statements, one of EACH of the followings: System.out.print("-"); // print # System.out.print("+"); // print + System.out.println(); // print a newline Your code must work exactly like the following example (the text in bold...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
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...
Create a MIPS program where you ask a user for 10 digit base 28 number and...
Create a MIPS program where you ask a user for 10 digit base 28 number and output a decimal in mips programming. It should also ignore any character that is not in the base 28 system and count its value as 0. Example: Input: 100000xza! Output: 17210368 Input: xyzxyzxyzx Output:0 Input: 1000000000 Output: 17210368 Output: 10578455953408 Input: 0000000000 Output:0
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all user information from a given input file. The input file contains information of a user in following order: username, first name, last name, password, account number and account balance. Information is separated with ‘|’. o username is a unique information, so no two users will have same username. Sample input file: Username eaglebank has password 123456, account number of BB12 and balance of $1000....