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
Which of the following types of networks encrypts data for transmitting over
vova2212 [387]

Answer:a

Explanation:

3 0
3 years ago
A ___ is a mobile device that typically ranges from seven to ten inches in size.
Ber [7]

A tablet computer, or commonly known as tablet,  is a mobile device that typically ranges from seven to ten inches in size. It has mobile operating system and LCD touchscreen display processing circuitry. The touchscreen display is operated by  finger. The tablet has many all of the functionalities of a computer, but not all of them.


3 0
4 years ago
Although saying "Cylinder IS A Circle" doesn't make sense, it can be implemented in Java using inheritance in a legitimate way.
allochka39001 [22]

Answer:

I've included in the codes the area to circle and volume to cylinder. The Volume method that was used, area() to compute, the volume of cylinder which shows that cylinder is an expansion of circle with an extra dimension (height)

Explanation:

Temp is tester class

public class Temp {

   public static void main(String[] args) {

       Circle c = new Circle(7);

       System.out.println("Area of circle with radius 7 is "+c.area());

       Cylinder c1 = new Cylinder(7,10);

       System.out.println("Cylinder volume with radius 7 and height 10: "+c1.volume());

   }

}

----------------------------------------------------------------------------------------------------

class Circle{

   int radius;

   Circle(int r){

       radius=r;

   }

   double area(){  //area of circle

       return 3.14*radius*radius;

   }

   public int getRadius() {

       return radius;

   }

   public void setRadius(int radius) {

       this.radius = radius;

   }

}

class Cylinder extends Circle{

   int height;

   Cylinder(int r, int h){

       super(r);

       height=h;

   }

   double volume(){  //volume of cylinder

       return area()*height;

   }

   public int getHeight() {  //accessor

       return height;

   }

   public void setHeight(int height) {  //mutator

       this.height = height;

   }

}

8 0
4 years ago
Becca is working on a program that will store data. The program will need quick access to data and data persistence is not impor
tester [92]

Answer:

A developer wants to take existing code written by another person and add some features specific to their needs.

Explanation:

pls Mark as Brain list

3 0
3 years ago
The key to security policy is being able to measure compliance against a set of controls. Security controls define _____ ______
Virty [35]

Answer:

The correct words for the blank spaces are: how; why.

Explanation:

In computer science, security control implies all the efforts of how organizations prevent, detect, and attack risks to safeguard sensitive information. Security policies establish why those actions are taken and set a list of all the assets that must be protected in front of a breach.

8 0
4 years ago
Other questions:
  • Question # 6
    13·1 answer
  • Text filters allow you to create a custom filter to match ________ the text in a field that you specify.
    7·1 answer
  • Which license enables anyone on the network to install and use the software?
    14·1 answer
  • printArray is a function that has two parameters. The first parameter is an array of element type int and the second is an int,
    10·1 answer
  • What to do when you strip a screw
    10·2 answers
  • Create a class called Hangman. In this class, Create the following private variables: char word[40], progress[40], int word_leng
    11·1 answer
  • Explain Spreadsheet and its Basics
    13·1 answer
  • Trevor owns a manufacturing business that makes specialized hiking and rock climbing gear. He is a very small player in the mark
    8·1 answer
  • You are on vacation with your family and have been nominated to be the family photographer. You have a 13.1-megapixel camera. Wh
    12·2 answers
  • SHORT ANSWERS:
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!