Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Project Issue

Options
  • 10-03-2016 3:34pm
    #1
    Registered Users Posts: 410 ✭✭


    Hi All,

    Doing a H/dip in computing and first time programming,

    building a bank app for my FYP but when i Create a new customer in BankSYS GUI when running, the setters and getters on firstName and secondName arent working.

    Looked at the code, even got 3 ppl from the class to check out the code as I have tested my Customer class each stop.

    Link to google file:
    https://drive.google.com/open?id=0B6YiumkjwnDITVdwLWNpNFpZQnc


    any help regarding this would be great :)


Comments

  • Registered Users Posts: 7,236 ✭✭✭mcmoustache


    DaraDali wrote: »
    Hi All,

    Doing a H/dip in computing and first time programming,

    building a bank app for my FYP but when i Create a new customer in BankSYS GUI when running, the setters and getters on firstName and secondName arent working.

    Looked at the code, even got 3 ppl from the class to check out the code as I have tested my Customer class each stop.

    Link to google file:
    https://drive.google.com/folderview?id=0B6YiumkjwnDITVdwLWNpNFpZQnc&usp=sharing


    any help regarding this would be great :)


    I can't see your code for some reason as I can't connect. Office firewall probably.

    Anyway, I would guess that your setter is something like:

    public void setFirstName(String firstName){

    firstName = firstName;

    }

    it should be more like

    public void setFirstName(String firstName){

    this.firstName = firstName;

    }


  • Closed Accounts Posts: 8,016 ✭✭✭CreepingDeath


    The Development forum would get you more answers.

    But assuming you haven't fixed the problem already,
    I didn't see anything wrong with the getters and setters.

    However you're setting a field to the result of a function call.

    Customer c1 = new Customer();
            
            c1.setFirstName(JOptionPane.showInputDialog(null, "What is the 
    Customers First Name:"));
    

    Just in case there's any subtle issues assigning stack elements to your fields,
    trying creating a new string from the JOptionPane return.
    c1.setFirstName(new String(JOptionPane.showInputDialog(null, "What is the 
    Customers First Name:")));
    


  • Registered Users Posts: 410 ✭✭DaraDali


    The Development forum would get you more answers.

    But assuming you haven't fixed the problem already,
    I didn't see anything wrong with the getters and setters.

    However you're setting a field to the result of a function call.

    Customer c1 = new Customer();
            
            c1.setFirstName(JOptionPane.showInputDialog(null, "What is the 
    Customers First Name:"));
    

    Just in case there's any subtle issues assigning stack elements to your fields,
    trying creating a new string from the JOptionPane return.
    c1.setFirstName(new String(JOptionPane.showInputDialog(null, "What is the 
    Customers First Name:")));
    


    Thanks so much to both of ye for the quick replies didn't know that you could put New String like that :)

    Ill try the fix you suggested at college in the morning and post back, If any MOD could move this to the Development forum, please do


  • Registered Users Posts: 772 ✭✭✭maki


    Both name setters (and your Customer constructor) have typos. Be aware of case sensitivity.
    public void setFirstName( String [U]firstname[/U]) {
        this.firstName = [U]firstName[/U];
    }
    
    public void setLastName( String [U]lastname[/U]) {
        this.lastName = [U]lastName[/U];
    }
    


  • Registered Users Posts: 410 ✭✭DaraDali


    The Development forum would get you more answers.

    But assuming you haven't fixed the problem already,
    I didn't see anything wrong with the getters and setters.

    However you're setting a field to the result of a function call.

    Customer c1 = new Customer();
            
            c1.setFirstName(JOptionPane.showInputDialog(null, "What is the 
    Customers First Name:"));
    

    Just in case there's any subtle issues assigning stack elements to your fields,
    trying creating a new string from the JOptionPane return.
    c1.setFirstName(new String(JOptionPane.showInputDialog(null, "What is the 
    Customers First Name:")));
    


    Just tried solution there sadly same result


  • Advertisement
  • Registered Users Posts: 410 ✭✭DaraDali


    maki wrote: »
    Both name setters (and your Customer constructor) have typos. Be aware of case sensitivity.
    public void setFirstName( String [U]firstname[/U]) {
        this.firstName = [U]firstName[/U];
    }
    
    public void setLastName( String [U]lastname[/U]) {
        this.lastName = [U]lastName[/U];
    }
    

    Thanks so much Maki, Can't tell you how long I spend looking for this error, because I had the CustomerTest.class that tested the customer.class and it wasn't throwing me any error's.

    I needed this working by next Wed as it's the first submission part of the FYP.

    My lecture encourages us to write about the errors we run into, I think he will love this :)


  • Registered Users Posts: 870 ✭✭✭moycullen14


    DaraDali wrote: »
    Thanks so much Maki, Can't tell you how long I spend looking for this error, because I had the CustomerTest.class that tested the customer.class and it wasn't throwing me any error's.

    I needed this working by next Wed as it's the first submission part of the FYP.

    My lecture encourages us to write about the errors we run into, I think he will love this :)

    Hi,

    Look on the bright side, You will probably never make this mistake again.

    I wouldn't be a great fan of IDEs but Java is one language where an IDE is essential. Keeping track of dependencies and build ordering with Java can be very tricky without an IDE.

    Another advantage of an IDE (e.g. eclipse) is that it would have flagged that error - at least as a warning - saying the assignment had no effect.


  • Registered Users Posts: 410 ✭✭DaraDali


    Hi,

    Look on the bright side, You will probably never make this mistake again.

    I wouldn't be a great fan of IDEs but Java is one language where an IDE is essential. Keeping track of dependencies and build ordering with Java can be very tricky without an IDE.

    Another advantage of an IDE (e.g. eclipse) is that it would have flagged that error - at least as a warning - saying the assignment had no effect.

    Ya using a IDE, started off with JCreator and now that I'm using Netbeans I just dont know myself,

    the weird thing with the issue I had above was I completely tested my Customer.class in the CustomerTest.class and it was running perfectly ;)

    All my Get/set methods worked :)

    Got most of my classes linked to my GUI and submitting the first part of my FYP today.


Advertisement