Hi,

I am sorry for the mix-up. My question is a Java programming question.

I write the following Customer class and it does not compile:


public class Customer
{
// instance variables
private String name;
private int refNumber;

/**
* Constructor for objects of class Customer
*/
public Customer()
{
// initialise instance variables
name = "";
refNumber = 0;
}

/**
* Another constructor
*/
public Customer(String name, int refNumber)
{
this.name = name;
this.refNumber = refNumber;
}

//Implicitly throws numberFormatException
public Customer(String name, String refNumber)
{
name = name;
refNumber = refNumber;
}

/**
* @return name The customer name
*/
public final String getName()
{
return name;
}
/**
* @param name Set name Sets the Customer's name
*/
public void setName(String name)
{
name = name;
}

/**
*@param refNumber Set Customer's reference number
*/
public void setRefNumber(int refNumber)
{
refNumber = refNumber;
}

/**
*@param refNumber Return refNumber The customer's number
* Implicitly throws NumberFormatException
*/
public void setRefNumber(String refNumber) throws NumberFormatException
{
try
{
//throw new NumberFormatException ("Bad Customer reference provided!");
refNumber = Integer.parseInt(refNumber);

}
catch (NumberFormatException e)
{

//System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
//throw new NumberFormatException(e);
}

finally
{

}
}
/**
*@Return refNumber
*/
public final String getRefNumber()
{
return Integer.toString(refNumber);
}

//Main method
public static void main(String[] args)
{
Customer customer = new Customer("Amos Akinyemi", "UJ3154");
System.out.println("Name: " + customer.getName());
System.out.println("Reference Number: " + customer.getRefNumber());
}

}

The method causing the error is the public void setRefNumber(String refNumber)

I thought if I convert the String to integer with:
refNumber = Integer.parseInt(refNumber);

the code should work. I don't know why it is not working.

Akinyemi