0

Relatively new to code...I'm trying to create a transaction method but when I call on the class I get an error; I have created an arraylist to hold accounts object and it has worked in other parts of my code however it is not recognised in this method..

ArrayList<BankSystem> account = new ArrayList<>();

This is the code:

public void cashTrans(ActionEvent e)
{
  if(txtAmount.getText().isEmpty()) //Check if TextField is empty
  {
     txtOutput3.setText("You must enter amount of cash you wish to deposit or withdraw");   
  }
  else
  {
     double amount = Double.parseDouble(txtAmount.getText()); //Get amount from TextField

     if(e.getSource()==btnDeposit) //If Deposit Money button is Clicked
     {
        account.depositToShares(amount); //Call on method depositToShares
     }
     else if(e.getSource()==btnWithdraw) //If Withdraw Money button is clicked
     {
        account.withdrawFromShares(amount); //Call on withdrawFromShares
     }
     txtOutput3.setText("Your new balance is $"+ account.getShareBalance()); //Confirm new balance
  }
     }

errors consist of:
BankSystemTester.java:317: error: cannot find symbol
        account.depositToShares(amount); //Call on method depositToShares
               ^
symbol:   method depositToShares(double)
location: variable account of type ArrayList<BankSystem>
BankSystemTester.java:321: error: cannot find symbol
        account.withdrawFromShares(amount); //Call on withdrawFromShares
               ^
symbol:   method withdrawFromShares(double)
location: variable account of type ArrayList<BankSystem>
BankSystemTester.java:323: error: cannot find symbol
     txtOutput3.setText("Your new balance is $"+ account.getShareBalance()); //Confirm new balance
                                                        ^
symbol:   method getShareBalance()
location: variable account of type ArrayList<BankSystem>
3 errors

methods in banksystem class public void depositToShares(double amount) { shareBalance = shareBalance + amount; } public void withdrawFromShares(double amount) {

  if(amount < shareBalance)
  {
     shareBalance = shareBalance - amount;     
  }
} 

I am using the arraylist to add, delete and find members but don't seem to have control of any of the methods in the class...any advice would be appreciated!your text

James_D
  • 201,275
  • 16
  • 291
  • 322
  • 2
    [mcve] please .. anyway, the error tells you exactly what's wrong: account is-a List .. (which has no method withdraw) - you probably want to access the content of the list at a particular index. Be sure to undersand List api, nothing special to fx - just plain java :) – kleopatra Apr 14 '23 at 14:55
  • 1
    [What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?](https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-or-cannot-resolve-symbol-error-mean) – Abra Apr 14 '23 at 17:02
  • If `account` is an object of type [ArrayList](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/ArrayList.html), then it does not have a `depositToShares` method. – Abra Apr 14 '23 at 17:03

0 Answers0