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