Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2006
    Posts
    26

    Unanswered: Integer Instance Variable for Customer Class

    Hi,
    I got a class for Customer class from a book. When I add the main method to the class and compile the program, the following errors were reported:

    "Incompatible types - found int but expected java.lang.String"

    Below is the class:

    /**
    * @author Amos Akinyemi
    * @version 1.0; 22 July, 2012
    */
    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 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
    {

    refNumber = Integer.parseInt(refNumber);

    }
    catch (NumberFormatException e)
    {

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

    finally
    {

    }
    }
    /**
    *@Return refNumber
    */
    public 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() method
    refNumber is an instance variable of the Custome class.
    How do I solve the problem?

    Thank you

    Akinyemi

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what do you think is wrong with the code...?

    incidentally this looks like a Java question not a MySQL question, as at no point do you refer to a SQL back end.

    Do you want the question moving to the Java section

    hint: you have specified a string as the customer number, yet the class expects an integer
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    nevermind

    aside: why is there no DELETE function for a post?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •