write a code in java Complete the program below so that it that takes a North American
Fantastic news! We've Found the answer you've been seeking!
Question:
write a code in java
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
public class PhoneNumberFormat public static void main String args String phone ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these electrical engineering questions
-
Java Question: Disk space AnalysisPlease advise the code in Java 7 or 8 2. Disk Space Analysis A company is performing an analysis on the computers at its main office. The computers are spaced along...
-
Code in JAVA SWING You are to build a Java app for a specialised calculator. The interactivity of this calculator is through a Java GUI. The calculator should resemble the features of a proper...
-
Write this code in java and also write comments and if possible do in eclipse. and paste this code in google drive or send screenshot and copypasted code as well. also show output. Add to the class...
-
Requirement 1 Two contribution format statements: current and proposed based on business decision. Requirement 2 For each option current and proposed business decision) calculate the following: a....
-
It is impossible to use DCF methods for evaluating investments in R&D. There are no cost savings to measure, and we dont even know what products might come out of our R&D activities. This is a quote...
-
(a) Use the definition of a derivative to find f (2), where f(x) = x3 2x. (b) Find an equation of the tangent line to the curve y = x3 2x at the point (2, 4). (c) Illustrate part (b) by graphing...
-
Stone Brewing Co. is a San Diego brewer that has sold its beers for over two decades. Stone has maintained its trademark and brand from the beginning, registering the STONE mark in 1998. Stone has...
-
Ross Hopkins, president of Hopkins Hospitality, has developed the tasks, durations, and predecessor relationships in the following table for building new motels. Draw the AON network and answer the...
-
4. Ethan bought new car worth $60 000. After 5 years, the car was worth $35 429.40. Calculate the depreciation rate of the Ethan's car. [T4] [C2]
-
Assuming a lower specification limit of 47 grams and an upper specification limit of 53 grams, what is the process capability of this process? How many defects would you expect in one million bags?...
-
Your client, The Brisbane Telegraph Pty Ltd, is the publisher of a weekday afternoon newspaper entitled "The Brisbane Telegraph. The newspaper's headquarters is in Red Hill. The company began...
-
1 a. The elasticity of demand for Dy between points a and bis 1.80. Given the shift in demand, the elasticity between points a' and b'in Figure a =[ b. The elasticity of demand for D2 between points...
-
Given P(A) = 75, P(B) = .37 and P(AUB) = .90, a) Find P(A/B) 0.2775 Round your answer to 4 decimal places. b) Find P(A/B) Round your answer to 4 decimal places.
-
Explain the importance of the marketing mix the 4 P's and describe and discuss the 4 C's.
-
Give an example of a product with features that dont align with the purported benefits.
-
If a perfectly competitive firm is producing at a rate output where marginal cost exceeds price how can a firm increase its profit?
-
AI hilal firm has sales of $20,000.Profit margin of 5% and dividend payout ratio of 40%. What is the common size percentage for the dividends paid?
-
Show that, given a maximum flow in a network with m edges, a minimum cut of N can be computed in O(m) time.
-
Lisa Sizemore, a taxpayer in the 10-15 percent tax bracket, purchased stock as an investment on July 11, 2011. She sold the stock on July 9, 2012, 2 days before qualifying for the long-term holding...
-
Quince Interests is a partnership with a tax year that ends September 30, 2012. During that year, Potter, a partner, received $3,000 per month as a guaranteed payment, and his share of partnership...
-
If Charles, a 16-year-old child model, earns $50,000 a year and is completely self supporting even though he lives with his parents, can his parents claim him as a dependent? Why or why not?...
-
We are a global, science-led biopharmaceutical business. Return to shareholders Revenue from the sale of our medicines generates cash flow, which helps us fund business investment. It also enables us...
-
Our mission and supporting strategies The FRCs mission is to promote high quality corporate governance and reporting to foster investment. Why have we landed on this mission? The capital markets are...
-
National Express and Stagecoach are both major providers of transport services in the UK. Here we compare their accounts of financial performance in their UK Bus divisions. National Express plc UK...
Study smarter with the SolutionInn App