Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that prompts the user to enter a telephone number in the format

ID: 3723020 • Letter: W

Question

Write a program that prompts the user to enter a telephone number in the format ddd-ddd-dddd, where d is a digit [0-9]. This is the format for telephone numbers in North America.

Test that the input is in the correct format and further check if the phone number has a Canadian area code (see the list of Canadian area codes ). The program will report if the input is valid or not. If the input includes a Canadian area code, the program will display the name of the province or territory with that area code. The program will continue to process numbers until the user enters the letter q.

Explanation / Answer

Please specify the programming language. Also, you need to provide the data to pick to display the provine.

Nevertheless, this should answer your query:

import java.util.Scanner;

public class Exercise_04_21 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter a phone_number ");

String phone_numb = input.nextLine();

// Check whether the input is valid

boolean isValid =

(phone_numb.length() == 11) &&

(Character.isDigit(phone_numb.charAt(0))) &&

(Character.isDigit(phone_numb.charAt(1))) &&

(Character.isDigit(phone_numb.charAt(2))) &&

(ssn.charAt(3) == '-') &&

(Character.isDigit(phone_numb.charAt(4))) &&

(Character.isDigit(phone_numb.charAt(5))) &&

(Character.isDigit(phone_numb.charAt(7))) &&

(ssn.charAt(6) == '-') &&

(Character.isDigit(phone_numb.charAt(8))) &&

(Character.isDigit(phone_numb.charAt(9))) &&

(Character.isDigit(phone_numb.charAt(10)));

// Display result

System.out.println(phone_numb + " is " + ((isValid) ? "a valid " : "an invalid ")

+ "phone_number number");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote