Write a program called telephone.java that prompts the user to enter their phone number using the specific format: (xxx) xxx-xxxx. 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.
Telephone.java
import java.util.Scanner;
public class Telephone {
public static void main(String[] args) {
Scanner scan = new
Scanner(System.in);
System.out.println("Enter a
telephone number using the specific format: (xxx) xxx-xxxx:
");
String phone = scan.next();
if(phone.length() == 13) {
if(phone.charAt(0) == '(' && phone.charAt(4)==')'
&& phone.charAt(8) == '-') {
String firstNum = phone.substring(1,4);
String secondNum = phone.substring(5,8);
String thirdNum = phone.substring(9);
if(firstNum.matches("[0-9]+") &&
secondNum.matches("[0-9]+")&& thirdNum.matches("[0-9]+"))
{
System.out.println("Given
phone number is valid");
} else {
System.out.println("Given
phone number is invalid");
}
} else {
System.out.println("Given phone number is
invalid");
}
} else {
System.out.println("Given phone number is invalid");
}
}
}
Output:
Enter a telephone number using the specific format:
(xxx) xxx-xxxx:
(702)892-0516
Given phone number is valid
Write a program called telephone.java that prompts the user to enter their phone number using the...
Using Python, write a program that prompts the user to enter their age as an integer and then prints out a message that says I suspect you were born in the year xxxx where "xxxx" is the current year minus the age entered. An example run where the user entered 10 for their age, would look like this: Please enter your age as an integer: 10 I suspect you were born in 2009
This is Python
The program should accept input from the user as either 7-digit
phone number or 10-digit. If the user enters 7 characters, the
program should automatically add "512" to the beginning of the
phone number as the default area code. Dash (hyphen) characters do
not count in input character count, but must not be random. If the
user enters dashes the total character count must not exceed
12.
The program should not crash if the user enters invalid...
build a phone number from digits entered by your user. Your program will loop until 10 valid digits have been entered. It will then use those digits to display the phone number entered using the format: XXXXXXXXXX (or (XXX) XXX – XXXX for extra credit). The program will ask for a digit, it will check to see if the digit is actually between 0 and 9 inclusively. If so, the digit will be stored as the next number in the...
USING PYTHON - Write a program that calls a function that prompts the user to enter a real number. The function should verify that the user entered a valid real number, and should prompt the user to re-enter any invalid input. After a valid real number has been entered, the function should return the number as a number. To test your function, from a main function, call the function two separate times and print the sum of the two numbers...
Write a program named CheckMonth2 that prompts a user to enter a birth month and day. Display an error message that says Invalid date if the month is invalid (not 1 through 12) or the day is invalid for the month (for example, not between 1 and 31 for January or between 1 and 29 for February). If the month and day are valid, display them with a message. For example, if the month entered is 2, and the day...
Hi I have to write this in C and wasn't sure how! These are two separate codes to be done separately. Write a program that accepts data from the user in the form mm/dd/yyyy and then displays it in the form of yyyymmdd (see below). Enter a date (mm/dd/yyyy): 2/17/2011 You entered the data 20110217 Write a program that prompts the user to enter a telephone number in the form (xxx) xxx-xxxx and then displays the number in the format...
C# Visual Studios Create a GUI application that prompts users to enter a ten (10) digit phone number, with hyphens and parentheses included – this input should be validated as a phone number adhering to the (XXX)-XXX-XXXX format. Should the user input an incorrect format, an error message should print to screen and your phone number textbox should be highlighted in red. Should an appropriately formatted phone number be entered, an acceptance message should printed to screen and your phone...
write a c++ program that prompts a user for a number then attempts to allocate an array of as many integers as the user enters. In other words, the program might prompt the user with a line like: “How many integers would you like to allocate?” It should then allocate as many integers as the user enters. The program should then wait for the user to press enter before deleting the allocated array and quitting. We will use this time...
Write a program in visual c# program named CheckMonth that prompts a user to enter a birth month. If the value entered is greater than 12 or less than 1, display an error message; otherwise, display the valid month with a message such as 3 is a valid month.
Write a program in Python to solve the following task: In this project, you will build a phone number from digits entered by your user. Your program will loop until 10 valid digits have been entered. It will then use those digits to display the phone number entered using the format: XXXXXXXXXX (or (XXX) XXX – XXXX for extra credit). The program will ask for a digit, it will check to see if the digit is actually between 0 and...