# Phone Number Problem

• November 5th, 2013, 09:39 AM
digitalsystems
Phone Number Problem
In this program we are asked to request the user to enter a phone number in the following format:

(0xx)xxxxxxxxx

The first number must be 0 and there can be up to 4 digits inside the brackets (inculding the 0). The remainder is is a number between 5-7 digits long.

For example, lets assume that the user enters (055)123456

We are then trying to convert the number into the following format +353-55-123456 as an output

Where I am stuck at the moment is that I am trying to get the position index of where the character ")" is located so that I can split the number and allow me to produce the required output. However when I try and get the position of ")" i receive and error in the compiler saying "method Integer.parseInt(String is not applicable"
Can someone have a look an see if they can point me in the right direction?

Thanks

Code Java:

```import javax.swing.JOptionPane; public class Week8Q1 { public static void main(String [] agrs) { String x = ")"; String num2; String num3; String num1 = ""; String pattern = "\\(0[0-9]{1,3}\\)[0-9]{5,7}"; String num4 = "+353-"; String number = JOptionPane.showInputDialog(null, "Please enter a number using the following format \n(xxxx)xxxxxxx"); int length = number.length(); if (number.equals("")) JOptionPane.showMessageDialog(null, "You have not entered a valid number"); else if (!(number.matches(pattern))) JOptionPane.showMessageDialog(null, "You have not entered a number in a valid format"); else num1 = Integer.parseInt(x.indexOf(number)); num2 = number.substring(2,(num1+1)); num3 = number.substring((num1+1),length); JOptionPane.showMessageDialog(null, "Your number in international format is :\n " + num4 + num2 + num3);; } }```
• November 5th, 2013, 09:52 AM
Norm
Re: Phone Number Problem
Look at the API doc for what arg is required for the parseInt() method. Are you passing what it requires?
What does the indexOf() method return?
What value do you want to assign to num1? Does the parseInt() method return that type of data?

The API doc is here: Java Platform SE 7

You should take some time to read the API doc for the methods you are trying to use. Their usage in the code does not make sense.