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 Programmers - Assistance needed.

Options
  • 12-12-2005 5:37pm
    #1
    Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭


    Hey,

    Im studying a degree course in computing - 1st year - and we have a programming assignment in Java to be completed. Im having some problems linking one of my classes with another class, and no matter what I do it fails me.

    Our assignment is to make a "Bank" System. Its fairly tough but I have a lot done so far.

    There are 3 classes: Bank (does most of the work by calling other classes etc), Customer and Account.

    Im trying to link the Bank Class with the Account class for adding money to an account. I can add customers, and add accounts to specific customers, and add money but not to a sepcific customer. So basicaly, im trying to get the bank to look at the Account class for the code to add cash to a specific customers account (ill give it the ID). I used linear search for adding specific accounts to customers.

    Can someone explain the way to go about this? Im not great with programing so far, so bare with me if you can This is Object Oreintated Java using BlueJ.

    Hope someone can give us a hand with this, as its really pi**ing me of!

    Thanks :d


Comments

  • Registered Users Posts: 2,297 ✭✭✭Ri_Nollaig


    blueJ is really annoying...

    so does the bank contain an array of customers?
    u said linear search so how about something like this:
    i assume the ID is a string (e.g. A124 r something) and getID( ) and addAmount(int) r two methods u have already done

    public void addAmount( int amount, String id ) {
    for( int i = 0; i < arraysize; i++ )
    if( customerArray[ i ].getID( ).equals( id ) )
    customerArray[ i ].addAmount( amount );
    }

    if this is complete crap feel free to shout at me :)


  • Closed Accounts Posts: 603 ✭✭✭shamrock2004


    Ri_Nollaig wrote:

    public void addAmount( int amount, String id ) {
    for( int i = 0; i < arraysize; i++ )
    if( customerArray[ i ].getID( ).equals( id ) )
    customerArray[ i ].addAmount( amount );
    }

    error there in the customerArray.addAmount(amount); as addAmount takes two parameters and i dont know why you are calling customerArray.addAmount(amount) again in the method addAmount.

    Sully04, can you post what you have already, as people on these forums can be mighty apprehensive when it comes to helping students with programming problems.They sometimes dont believe that people are making the effort! regards
    Shamrock


  • Closed Accounts Posts: 324 ✭✭madramor


    error there in the customerArray.addAmount(amount); as addAmount takes two parameters and i dont know why you are calling customerArray.addAmount(amount) again in the method addAmount.

    one is add amount in bank class
    other
    is add amount in customer class

    the add amount in the bank takes 2 inputs amount and id
    it then scans through the array of customers to find the
    one with the corresponding id and calls the add amount method
    on that customer.

    The bank class should use an ArrayList rather than an array to
    store the customers, as the number of customers can grow as
    the user enters more


  • Closed Accounts Posts: 603 ✭✭✭shamrock2004


    whoops my bad!tis late you know! :D
    Ok why not use a HashMap when you want to create a customer. have the unique customer Id (String) as the key and the account balance (double) as the value. Now when you create a customer (method Customer.createCustomer called in bank) simply supply the customer id (the account balance is set to 0.0 by default by you). Then you can call the method Account.updateAccountBalance (for example) from bank and supply the customer id and the amount you want to asssign to the balance as parameters. You then scan through the keys of the HashMap and if the key is present, it means the customer Id has been found. Next pull out the account balance (double) and update it.
    The hashmap will look like this (for example:
    {JoeBloggs2005=52.33, BartSimpson2005=21.54}
    Here you can see the customer id JoeBloggs and BartSimpson, they can be anything you like!
    Its nice and neat as you are only playing around with the customer id and the balance and these two map to each other naturally!best of luck
    Shamrock


  • Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭Sully


    Ah sorry for the delay lads, iv been coding this all night and I just handnt the time. I had someone explaining to me (not giving me the answers, which is what I prefer). Iv given up on it and submitted it in as its been driving me nuts for ages. But, id still be interested to know what went wrong so ill submit the code in a bit. I know people will think "Bah, all he wants is for him to do his homework". Thats not what im looking for, im not a programmer (yet anyway :P) and I need someone to explain whats going wrong (even tho ill still be lost at some of the termonolgy, bare with me :)) so I myself can think of a solution to fix it.

    And on the note of BlueJ - it seems pretty good, but at times drives me mental but that code just be my poor coding :P Ill post up the code in a min, let me get it together


  • Advertisement
  • Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭Sully


    Here is a simple class diagram for each of my three classes; Bank, Customer & Account. I done this without the aid of a program

    http://pastebin.com/462200

    Here is the code I used in the classes for adding money to an account;

    http://pastebin.com/462202 - Contains the FindCustomer() linear search and the first part of the insertMoney() method. The method then links up to the Customer class. Code in the customer class:

    http://pastebin.com/462205 - Contains the FindAccount() linear search (gotta find the account we want to add money to as we have the customer) and the second part of the insertMoney() method. The method will then link up to the final code in the account class:

    http://pastebin.com/462208

    Hope they work anyway. Dont know the expiry time on pastebin. Cheers in advance :)


  • Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭Sully


    Hey all.

    Iv just went through the project with the lecturer and I asked why I was having problems with my code. It took a while to figure it out, but in the end I realised it wasnt broken.

    The problem was, when I was creating a bank account - the code said to give the first bank account the ID of 2000, and increase for each new account. I forgot I had that built-in, so programmed it in so I set the account number. So when I went to add cash to the account, it wasnt going into the account because the number I gave it (which I had set earlier) didnt match the number the system gave it (which I had programed in earlier on).

    Cant believe I missed it to be honest, but the good thing was I got a LOT of the assignment working - just by getting that piece of code to work :P Some of the classes worked around the account balances and stuff aswel. Only small bits and pieces were left to do, but I wasnt able to complete.

    If anyone wants to see all my code, the assignment requirements etc. I have no problem uploading. Just ask :)

    Thanks for your help


  • Site Banned Posts: 44 thehurricane


    "mod" Khannie


Advertisement