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 FYP

Options
  • 11-04-2016 1:03pm
    #1
    Registered Users Posts: 410 ✭✭


    Hi All,

    Doing a banking java app for my FYP of my Hdip.

    Following on from this thread : http://www.boards.ie/vbulletin/showthread.php?p=99019831

    Just need to add images to the JMenuItem just for save/load/quit have the images in the program files and looked at stack overflow so many times now and just cant seem to get it to work.

    Also is there any way to choose a account from a array list so I could call a withdraw () or deposit () methods ? I was thinking I could choose a array list object (Account 4 from a list ) and then deposit or withdraw from that account.

    thanks again
    D


Comments

  • Registered Users Posts: 262 ✭✭guylikeme


    DaraDali wrote: »
    Hi All,

    Doing a banking java app for my FYP of my Hdip.

    Following on from this thread : http://www.boards.ie/vbulletin/showthread.php?p=99019831

    Just need to add images to the JMenuItem just for save/load/quit have the images in the program files and looked at stack overflow so many times now and just cant seem to get it to work.

    Also is there any way to choose a account from a array list so I could call a withdraw () or deposit () methods ? I was thinking I could choose a array list object (Account 4 from a list ) and then deposit or withdraw from that account.

    thanks again
    D


    HashMap would be your best bet. Use the account name as key.

    So would be declared by
    Map <String, Account> accountNamesMap = new HashMap<String, Account>();
    accountNamesMap.put("guylikeme", new Account("guylikeme", 10000000));
    accountNamesMap.get("guylikeme").withdraw(10);


  • Registered Users Posts: 410 ✭✭DaraDali


    guylikeme wrote: »
    HashMap would be your best bet. Use the account name as key.

    So would be declared by
    Map <String, Account> accountNamesMap = new HashMap<String, Account>();
    accountNamesMap.put("guylikeme", new Account("guylikeme", 10000000));
    accountNamesMap.get("guylikeme").withdraw(10);

    Thanks guylikeme for the quick reply, been thinking of a way to build it, Ill check this out tomorrow and get back and update the code :rolleyes:

    So will I use a HashMap instead of arraylist? or does a HashMap pull from a arraylist?


  • Registered Users Posts: 262 ✭✭guylikeme


    DaraDali wrote: »
    Thanks guylikeme for the quick reply, been thinking of a way to build it, Ill check this out tomorrow and get back and update the code :rolleyes:

    So will I use a HashMap instead of arraylist? or does a HashMap pull from a arraylist?

    The former. It's basically an arraylist with keys instead of index numbers. Google hashmap examples, copy paste and edit as appropriate 😀


  • Registered Users Posts: 410 ✭✭DaraDali


    guylikeme wrote: »
    The former. It's basically an arraylist with keys instead of index numbers. Google hashmap examples, copy paste and edit as appropriate 😀

    Will do, thanks for the input :) only things we have done so far are lists and arraylists and couldn't get it to work just using that!


  • Registered Users Posts: 410 ✭✭DaraDali


    guylikeme wrote: »
    The former. It's basically an arraylist with keys instead of index numbers. Google hashmap examples, copy paste and edit as appropriate 😀

    Still having some trouble with implementing hashmaps along side my arraylists.

    I attached a example screenshot:


  • Advertisement
  • Registered Users Posts: 262 ✭✭guylikeme


    DaraDali wrote: »
    Still having some trouble with implementing hashmaps along side my arraylists.

    I attached a example screenshot:

    To that post? Not seeing it


  • Registered Users Posts: 8,800 ✭✭✭Senna


    If the array of objects are accounts, can you not call
    For(int I : : )
    If acount[ I ].getAccount number() == search;
    account[ I ].withdraw(amount);

    Or do you have to know is it an "instance of" a certain type of account before withdraw is correct.

    I had to do a similar banking project with an array of accounts, hashmaps would have been handy but at that stage of learning hashmaps and iterators wouldn't have even be mentioned let alone taught.
    I can't see your code as I'm on the phone.


  • Registered Users Posts: 410 ✭✭DaraDali


    guylikeme wrote: »
    To that post? Not seeing it

    Updated my src files. The boards file uploader had some issues the other day :D

    I have the Hashmap in place but now its not saving my arraylists to a file.



    Bank.zip


    HashmapCustomer.PNG

    hashmap2.PNG

    Also got the images working :) When I was calling the setIcon method I never created the image new image !!!! I think i used ever constructor out there before I figured it out...


  • Registered Users Posts: 410 ✭✭DaraDali


    Senna wrote: »
    If the array of objects are accounts, can you not call
    For(int I : : )
    If acount[ I ].getAccount number() == search;
    account[ I ].withdraw(amount);

    Or do you have to know is it an "instance of" a certain type of account before withdraw is correct.

    I had to do a similar banking project with an array of accounts, hashmaps would have been handy but at that stage of learning hashmaps and iterators wouldn't have even be mentioned let alone taught.
    I can't see your code as I'm on the phone.


    Ya at this stage Hashmaps are not needed, but there is a 10% for independent learning for the project so my lecturer encouraged me to do Hashmaps after seeing I was trying to implement them the other day :)

    I blame guylikeme :D But After seeing hashmaps I like them, if I could just get them to work

    Sorry for the slow replies, Have about 4 other projects and this is the last one I have to submit but does carry 10credit :)


  • Registered Users Posts: 306 ✭✭yes there


    In your map you are using the first name as key. That is bad. Hashmaps work by hashing the key. Adding two names of the same name will be problematic. If you want to do it this way just use the customer as key. In the customer class you implement the hashcode and equals method. Again google is your friend. Should help towards extra 10%.

    There is a standard rule called is a has a rule for class relationships best practice.
    Example an account is not a customer so you would never extend it.
    But a customer has an account so you could have it as a class member. Your standard array will work nicely with this as you can call the account methods on that member with your customer reference.

    As you have a savings account also then what your teacher wants you to do is create an abstract account class and extend that class with current account and savings account class. Ensure only the required.

    Iterate your list of customers and find the one you want then call this
    example [PHP]customer.getAccount.deposit(double deposit){logic}[/PHP]

    From what I see id guess you will be marked on the java basics i.e. classes, dependancies, flow control etc. I'd definitely change your class relationships anyway.

    NB your arraylist of customers is saving on my machine :)


  • Advertisement
  • Registered Users Posts: 410 ✭✭DaraDali


    yes there wrote: »
    In your map you are using the first name as key. That is bad. Hashmaps work by hashing the key. Adding two names of the same name will be problematic. If you want to do it this way just use the customer as key. In the customer class you implement the hashcode and equals method. Again google is your friend. Should help towards extra 10%.

    There is a standard rule called is a has a rule for class relationships best practice.
    Example an account is not a customer so you would never extend it.
    But a customer has an account so you could have it as a class member. Your standard array will work nicely with this as you can call the account methods on that member with your customer reference.

    As you have a savings account also then what your teacher wants you to do is create an abstract account class and extend that class with current account and savings account class. Ensure only the required.

    Iterate your list of customers and find the one you want then call this
    example [PHP]customer.getAccount.deposit(double deposit){logic}[/PHP]

    From what I see id guess you will be marked on the java basics i.e. classes, dependancies, flow control etc. I'd definitely change your class relationships anyway.

    NB your arraylist of customers is saving on my machine :)

    Can I start by saying thanks "yes there" for taking the time and effort in writing such a clear and well defined reply,

    Just cleared up the extends customer into account and working on making it abstract for the subclasses at the moment thanks for the comments on that :) we barely touched on abstract classes, doing a hdip in Java we are moving quick quick :D

    Still trying to wrap my head around the hashmap ideas you talked about. Ill work on it tomorrow.

    Btw would love to get you opinion on my loop method I have for blocking blank input from a user.

    heres the method :
    [PHP]
    private String getNonBlankInput(String prompt) {
    String input = JOptionPane.showInputDialog(prompt);

    while (input.equals("")) {
    JOptionPane.showMessageDialog(null, "Cannot accept blank entries!");
    input = JOptionPane.showInputDialog(prompt);
    }

    return input;
    }[/PHP]

    so when asking for customer data I call the method here :

    [PHP]Customer c1 = new Customer();

    c1.setFirstName(JOptionPane.showInputDialog(null, getNonBlankInput("What is the Customers First Name:")));[/PHP]

    Is this an accepted way to validate data input? Seems to work ok so far :rolleyes:


  • Registered Users Posts: 306 ✭✭yes there


    No problem. If it works it is an acceptable way, another question is can it be done better, you should always be asking yourself this. If I was doing it I would compare against a regular expression and not an empty string. Reg Exs at first appear difficult but they are easy with practice. You would use the The pattern and matcher class for this.

    As an added learning experience Id stress you to look up the docs for both of these classes before you go googling the solution. In most of your development life you will be using libraries so understanding how to read and use classes like these at this stage will really help you.


  • Registered Users Posts: 410 ✭✭DaraDali


    yes there wrote: »
    No problem. If it works it is an acceptable way, another question is can it be done better, you should always be asking yourself this. If I was doing it I would compare against a regular expression and not an empty string. Reg Exs at first appear difficult but they are easy with practice. You would use the The pattern and matcher class for this.

    As an added learning experience Id stress you to look up the docs for both of these classes before you go googling the solution. In most of your development life you will be using libraries so understanding how to read and use classes like these at this stage will really help you.

    Thanks Again. I did the suggestions that you suggested :cool:

    Im the only one in the class that's using Abstract classes in my project, also I think i have Customer/savingAccount and CurrentAccount all with hashmaps now.

    Also I cleared up the relationship with account inheirating from Customer. I intend to talk about that i my documentation.

    Just need to figure out how to iterate through them now :)

    Also added some icons and some input validations for setAge();


  • Registered Users Posts: 410 ✭✭DaraDali


    DaraDali wrote: »
    Thanks Again. I did the suggestions that you suggested :cool:

    Im the only one in the class that's using Abstract classes in my project, also I think i have Customer/savingAccount and CurrentAccount all with hashmaps now.

    Also I cleared up the relationship with account inheirating from Customer. I intend to talk about that i my documentation.

    Just need to figure out how to iterate through them now :)

    Also added some icons and some input validations for setAge();

    Also having some issues with loading my saved files into my program, is there any way to do this automatically?

    I have this method:

    [PHP] public static void getCustomers(ArrayList myCustomers) throws FileNotFoundException, IOException, ClassNotFoundException {
    ObjectInputStream is = new ObjectInputStream(new FileInputStream("Customer.data"));
    myCustomers = (ArrayList<Customer>) is.readObject(); // note the typecast
    is.close();
    }[/PHP]

    I called the method at the top on the top of my BankSYS file. but its not loading it


Advertisement