1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Helen [10]
4 years ago
13

Write a program called telephone.java that prompts the user to enter their phone number using the specific format: (xxx) xxx-xxx

x. The program should check whether the input entered is valid. The program must also check for the parenthesis () for the area code (the first three numbers). Example: (702)892-0516 would be correct but 702-892-0516 would not be correct. Example: Enter your phone number: 702-908-1333. 702-908-1333 is a NOT a valid phone number as there are no parenthesis (). Another example: Enter your phone number: (70 –290-8133 (70—290-8133 is NOT a valid phone number. If the entered telephone number is valid the program should return a statement that says the phone number is valid.
Computers and Technology
1 answer:
djverab [1.8K]4 years ago
8 0

Answer:

Following are the program in the Java Programming Language.

//import package scanner class

import java.util.Scanner;

//define class

public class telephone {

//define main method

public static void main(String[] args) {

//set object of the scanner class

Scanner sc = new Scanner(System.in);

//print message

System.out.println("Enter tele-phone no. using this format: (xxx)xxx-xxxx: ");

//get input from the user

String phn = sc.next();

//check length of phone number is equal to 13

if(phn.length() == 13) {

//check phone no. containing parentheses

if(phn.charAt(0) == '(' && phn.charAt(4)==')' && phn.charAt(8) == '-') {

//initializing the values

String num1 = phn.substring(1,4);

String num2 = phn.substring(5,8);

String num3 = phn.substring(9);

//check the following input is numeric or not

if(num1.matches("[0-9]+") && num2.matches("[0-9]+")&& num3.matches("[0-9]+")) {

//then, print valid message

System.out.println("Given phone number is valid");

}

//otherwise

else {

//print invalid message

System.out.println("Given phone number is invalid");

}

}

//otherwise

else {

//print invalid message

System.out.println("Given phone number is invalid");

}

}

//otherwise

else {

//print invalid message

System.out.println("Given phone number is invalid");

}

}

}

Explanation:

Following are the desciption of the program

  • Declared a class telephone
  • Read a input phone number in phn variable of string type.

Check the following condition of phone number

  •  if "phn"=="13" then it check for the parenthesis and number is valid otherwise phn number is invalid .
You might be interested in
How is a source file different from a "listing file"?
S_A_V [24]
E-filing<span> technical information - acceptable native (or </span>source<span>) electronic </span>file<span> format types. ... Whenever possible, the electronic </span>source<span> files used to create the PDF should be uploaded after the PDF in the same </span>filing<span>. Multiple </span>source<span> files can be uploaded in the same </span>filing<span>.</span>
8 0
3 years ago
What is the main theme of The hundred dresses​
iogann1982 [59]

Explanation:

The main theme of The hundred dresses is about the act of forgiving someone's mistake. i hope so

5 0
3 years ago
Read 2 more answers
Complete the sentence with the correct response.
Fiesta28 [93]

Answer:

Material systems developer typically combines the skills of a programmer with the multitasking expectations of developing 3 dimensional models of objects, enhancing the graphical effects.

6 0
3 years ago
What is the output of this program?
Leto [7]

Answer:

70 is the answer negative one begins from 83 and count down to 89, Therefore, 70 is is -4 and is chosen as the best answer

7 0
3 years ago
Differentiate between inherited trait and acquired trait​
miskamm [114]

Answer: Inherited trait is something you already have and acquired is something that you learn or achieve.

Explanation:

8 0
4 years ago
Other questions:
  • Joe wants to use an engaging image as a hook in his presentation , but he’s afraid of violating any copyright law. What should h
    10·1 answer
  •  When using cost-benefit analysis to determine the benefits of a community project, economists measure the value in terms of (A.
    14·1 answer
  • Welcome to Cypres...
    6·1 answer
  • How does a content management system differ from a basic wysiwyg web authoring tool??
    11·1 answer
  • Can you please help me by sending a proposal onnanotechnology in networking applications
    8·1 answer
  • A _ fire extinguisher should be used on a computer fire
    15·1 answer
  • What does the /var directory contain?
    7·1 answer
  • In which type of modulation is a 1 distinguished from a 0 by shifting the direction in whichthe wave begins?
    14·1 answer
  • If you change the text to bold,you are changing the what?
    9·1 answer
  • Which of the following commands should be used if a user does NOT want the header which has been created to appear on the first
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!