Question: 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

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

1 Expert Approved Answer
Step: 1 Unlock

public class PhoneNumberFormat public static void main String args String phone ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!