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"); 
            }

Recommended Answers

All 11 Replies

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

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...

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

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)

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.

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

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

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...

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?

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.