Answered step by step
Verified Expert Solution
Link Copied!

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
image

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Electrical Engineering questions

Question

=+b. What is Pd(2c ) when 5 4?

Answered: 1 week ago