Write a program that reads in a 10-digit phone number

Assignment Help Computer Engineering
Reference no: EM132217543

Question :

As of the year 2008, a 10-digit phone number that begins with either 800, 888, 877, or 866 is toll free.

Write a program that reads in a 10-digit phone number and displays a message that states whether or not the number is toll free.

For example:

Input: 8005651009

Output: 800-500-1009 is a toll-free number.

How do I change this to switch statement?

import java.util.Scanner;

public class Toll {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter a toll number: ");

long phone = sc.nextLong();

String number = Long.toString(phone);

if (number.startsWith("800") || number.startsWith("866") || number.startsWith("877") || number.startsWith("888")){

if(number.length() == 10){

String result = number.substring(0, 3);

result = result + "-";

result = result + number.substring(3,6);

result = result + "-";

result = result + number.substring(6);

System.out.println(result+" is a toll-free number.");

}else{

System.out.println("Not a valid phone number.");

}

}else{

System.out.println("Not a toll-free number");

}

}

}

Thanks

Reference no: EM132217543

Questions Cloud

Prepare your responses on the given post : Anders is 26 years old and single. He accepted a position with a global non-governmental organization (NGO) to work on a health project in Uganda.
Determine the minimum number of open areas needed : A zoo is going to place its animals in a set of large open areas, instead of having them in individual cages.
Prepare a contribution format income statement for the year : Assume that the company produces and sells 81,000 units during the year at a selling price of $9.93 per unit. Prepare a contribution format income statement.
Declare a class-level array that contains five employee : Define a structure named Employee. The structure should contain two member variables: a String variable to store the ID and a Double variable to store.
Write a program that reads in a 10-digit phone number : Write a program that reads in a 10-digit phone number and displays a message that states whether or not the number is toll free.
What type of account you used to record advance receipt : What is the type of account you used to record the advance receipt of money on Dec. 8th from North construction? Did the balance of that account change.
Calculate the factorial of a non-negative integer : Calculates the factorial of a non-negative integer, that is, the product of * all integers between 1 and the given integer, inclusive.
Compute the income from subsidiary : Preparing a consolidated income statementâ€"Equity method with noncontrolling interest, AAP and upstream and downstream intercompany inventory profits.
Prompts the user to enter a persons birth date in numeric : Use nested try-catch blocks to print the appropriate emor message fat the error in the internal try-catch block(s) Re-throw the exception.

Reviews

Write a Review

Computer Engineering Questions & Answers

  A program that asks the user for an amount of money

Write a JAVA program that asks the user for an amount of money (entered in cents) and then tells the user how to make change.

  Describe what numbers the following list comprehension

Using either words or mathematical set notation, describe what numbers the following list comprehension generates.

  Network in a gsm system

Consider two mobiles belonging to the same home network in a GSM system. Explain step by step the process in GSM roaming, when one mobile wakes up in a foreign network and makes a call to the other.

  Create a form button named create resume

Create a form button named Create Resume. When clicked this button should call a function that generates a new Web page displaying a resume based on the user input.

  Create multiple threads with runner functions

Create multiple threads with runner functions which include individual threads roles.

  Show the truth table for this function

Consider a logic function with three inputs, A, B, and C, and three outputs, D, E, and F . The function is defined as follows: D is true if A or C is true, E is true if A and C are true, and F is true only if B or C are false.

  Indicate the sequence of tracks visited and the total head

Suppose that the head of a disk with 256 tracks, numbered 0 to 255, is currently serving a request at track 58.

  Prompt the user to input the name of a text file

Write one program (C or C++) that will prompt the user to input the name of a text file and it will display how many lines are in the file.

  Case studies of mainframe to client-server engineering

Research the literature and/or Internet sources to find one or more papers that discuss case studies of mainframe to client-server reengineering. Present a summary.

  Write a program that prints a poem of your choice

Write a program that prints a poem of your choice. If you don't have a favorite poem, search the Internet for "Emily Dickinson" or "e e cummings".

  Define a contract with a managed security services

negotiate a contract with a managed security services (MSS) provider to outsource some of your company's security operations

  Draw the red-black bst

Draw the red-black BST that results when you insert items with the keys EASY QUTION in that order into an initially empty tree.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd