954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Editing an array List

Hi, So im trying to create a deposit method, but to no success. Can someone pls help me ??
This is my code for far:

static void depositCurrent (ArrayList<Current> CurrentListIn) 
    {
        System.out.println ("Enter account number you want to deposit money into"); 
        String accountNumber = EasyScanner.nextString();
        
        
        
        boolean flag = false; 
        
        
        double getBalance;
        String getID; 
        
        String getType;
        String getHID; 
        String getCID;
        String getName;
        for (Current item : CurrentListIn)  
        {
            getID = item.getAccountNumber(); 
            getBalance = item.getAccountBalance();
           
            getType = item.getAccountType();
            getHID = item.getAccountHolderID(); 
            getCID = item.getAccountClerkID();
            getName = item.getAccountHolderName();
            
            if (accountNumber.equals (getID)) 
            {
                System.out.println ("Enter amount to deposit: "); 
                double amountIn = EasyScanner.nextDouble();
                getBalance = getBalance+amountIn;
                System.out.println ("your new balance is: " + getBalance); 
                flag = true;
                
                int spot = CurrentListIn.indexOf (new Current (getID, getType, getHID, getName, getCID,getBalance));
               
               
                
            }
        CurrentListIn.add(new Current (getID, getType, getHID, getName, getCID,getBalance));
    }
    
     if (flag == false)
            {
                System.out.println ("id " +accountNumber+ "(m) is not found"); 
            }
kexkoj
Newbie Poster
7 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

I'm not really following your logic here. your deposit onto an account is an ArrayList???

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

The Account Balance already has a value, I want to add the amountIn (which is the deposit) to This value... Hope I made myself clear...

kexkoj
Newbie Poster
7 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

What is contained in a Current object?
Does it have methods for getting at its contents?

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 
What is contained in a Current object? Does it have methods for getting at its contents?


Yes I do have a method for getting its contents, In the current Array List I have attributes such as accontNumber , accountBalance, accountType, CustomerID etc...
Basically My problem is editing the array list, as I have to edit the accountBalance by adding the current account balance to the new amount deposited (amountIn)

kexkoj
Newbie Poster
7 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

To update the contents of an object in the array list, you need to search through the array list's contents until you find the object (based on an account number) and then call one of the object's methods to do the update.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

All that is fine, I search the array List, find the record I want to edit, edit it (the result even shows the new accountBalance), but the problem is saving the new vallue onto the arrayList

kexkoj
Newbie Poster
7 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

What new value? What is this "new value"?
Please explain when and why you are creating a new value?

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

yes, certainly. So I have this ArrayList, (CurrentListIn), which consists of accountBalance, AccountNumber, CustomerId, CustomerName, etc... Basically my program has the option to deposit money. Thus when depositing money the accountBalance obviuosly increases (accountBalance = accountBalance+amountIn). So therefore my problem is editing the accountbalance .... Hope I explained clearly...

kexkoj
Newbie Poster
7 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

I thought that the Current class contained the data and values.
The array list contains Current class objects, not the data.

What value are you updating when you make a deposit? Where is that value?

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

I am trying to update the "getBalance" (item.getAccountBalance), this object is the one that will be updated...

kexkoj
Newbie Poster
7 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

Never Mind I solved it, thanks anyway for your time :)

kexkoj
Newbie Poster
7 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You