Answered step by step
Verified Expert Solution
Question
1 Approved Answer
write a code in java Complete the program below so that it that takes a North American phone number in the format 999.999.9999 (where 9
write a code in java
Complete the program below so that it that takes a North American phone number in the format 999.999.9999 (where 9 is any number from 1-9) and displays it in the format +1 (999) 999-9999. For example, 204.867.5309 would be formatted as +1 (204) 867-5309. Write a static method named format () that accepts the string input as a parameter and returns the formatted phone number. You must: Validate that the input is formatted properly as 999.999.999. Your program should throw IllegalArgumentException for any of the following violations: the length of the string is not correct a dot is not in the right position a character is not a digit where applicable use an enhanced for loop to iterate through the characters Format the phone number: use the split () method to remove the dots - use the regular expression "\ \ ." use StringBuilder to reconstruct it into the new format in the following manner: iterate through the array to piece it back together e.g. 9999999999 place the characters +1 ()- accordingly public class PhoneNumber Format( public static void main (String[] args) { String phone = "204.867.5309"; System.out.println (format (phone)); } // add format method here
Step by Step Solution
★★★★★
3.52 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
public class PhoneNumberFormat public static void main String args String phone ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started