"PhoneNumberConversion"
First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).
Then create a new Java application called "PhoneNumberConversion" (without the quotation marks) based on the Horstmann textbook chapter 2 programming exercise called Business, P 2.23 on page 75, in the section on Programming Exercises near the end of Chapter 2, before the answers to the self-check questions.
Request the ten-digit phone number from the user at the command line.
The following pseudocode describes how to turn a string containing a ten-digit phone number (such as "4155551212") into a more readable string with parentheses and dashes, like this: "(415)555-1212". Take the substring consisting of the first three characters and surround it with "(" and ") ". This is the area code. Concatenate the area code, the substring consisting of the next three characters, a hyphen, and the substring consisting of the last four characters. This is the formatted number.
PhoneNumberConversion.java
import java.util.Scanner;
public class PhoneNumberConversion {
public static void main(String[] args)
{
Scanner scan = new
Scanner(System.in);
System.out.println("Enter the
ten-digit phone number:");
String phoneNum =
scan.next();
if(phoneNum.length() == 10 )
{
phoneNum =
"("+phoneNum.substring(0,3)+")-"+phoneNum.substring(3,
6)+"-"+phoneNum.substring(6,10);
System.out.println(phoneNum);
} else {
System.out.println("Invalid input. Phone number must contain 10
numbes");
}
}
}
Output:
Enter the ten-digit phone number:
4155551212
(415)-555-1212
"PhoneNumberConversion" First, launch NetBeans and close any previous projects that may be open (at the top...
First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "PasswordChecker" (without the quotation marks) that gets a String of a single word from the user at the command line and checks whether the String, called inputPassword, conforms to the following password policy. The password must: Be 3 characters in length Include at least one uppercase character Include at least...
First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "MultiDimensions" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the...
First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "MinMax" (without the quotation marks) that declares an array of doubles of length 5, and uses methods to populate the array with user input from the command line and to print out the max (highest) and min (lowest) values in the array. The methods that determine the max and min...
Write a function called "phoneNumberFormat" that takes a string containing a ten-digit phone number (such as 5155551212) as input, convert into a more readable string with parentheses and dashes like (515)555-1212 and display it. If the input string contains more than or less than ten characters, display an error message. Note: Steps of phoneNumberFormat function can be given as follows: def phoneNumberFormat (phoneNum): 1. Let l be the length of the phoneNum 2. If 1 does not equal 10 then,...
I need help with this assignment in C++,
please!
*** The instructions and programming style details
are crucial for this assignment!
Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...