Using a method from one class into another class

I am having trouble with my last method. I am informed that I have to use my adjust method from my BankAccount.class in my monthlyFee method in my bank class and I can not figure it out. I've tried multiple different things and can not get it to work. We need to adjust the balances of the accounts with the monthly fee.

Bank.java:33: error: method adjust in class BankAccount cannot be applied to given types; BankAccount.adjust(); ^
required: double found: no arguments reason: actual and formal argument lists differ in length 1 error

Bank.java:33: error: double cannot be dereferenced fee.adjust(); 1 error

Bank.java:33: error: cannot find symbol bank.BankAccount.adjust(); symbol: variable BankAccount location: variable bank of type BankAccount[] 1 error

BankAccount.class

public class BankAccount {

String owner; // owner of account
int accountNumber; // integer account number
double balance = 0.0; // account balance
double amount; // adjusted amount to balance
String balanceFmt = "%.2f"; // string format for 2 decimal places

public BankAccount(String owner, int accountNumber) { //Constructor for the bank account
   this.owner = owner;
   this.accountNumber = accountNumber;
}

public double adjust(double amount) { //method to adjust balance
   this.balance += amount;
   return balance;
}
public String toString() { // method to print out account info
   return owner + " owns the account " + accountNumber + " with the balance of $" + String.format(balanceFmt,balance);

}
public double getBalance() { // method to get balance of accounts
   return balance;   
}
}

Bank.class

public class Bank {

BankAccount bank[];

public Bank() { // constructor for making a 10 account array
   bank = new BankAccount[10];
}

public void addAccount(BankAccount accounts) { // add account for giving numbers to accounts
   for(int i = 0; i < bank.length; i++) {
      if(bank[i] == null) {
         bank[i] = accounts;
         break;
      }
   }
}

BankAccount getAccount(int i) { //obtain account from BankAccount class
   return bank[i];
}

public void printAccounts() { //prints out account statuses
   for(int i = 0; i < bank.length; i++) {
      if(bank[i] != null) {
      System.out.println(bank[i]);
      }
   }
}

public void monthlyFee(double fee) { //monthly fee for bank accounts
   for(int i = 0; i < bank.length; i++) {
      if(bank[i] != null) {
      } //I have tried BankAccount.adjust() and couldn't work, bank[i].adjust() nothing seems to work
   }
}
}

BankTest.class

public class BankTest { 
/*
 * test - set up a bank and add accounts
 */

public static void main(String[] args) {
// Code to test Bank and BankAccount classes
int errors = 0;
double fee = -2.95;

Assignment assignment = new Assignment();
assignment.homework("Homework 2a");

System.out.println("\nCreate bank1");
Bank bank1 = new Bank();
System.out.println("\nOne account");
BankAccount bankAccount1 = new BankAccount("Joe Mac", 1234);
bankAccount1.adjust(1000.0);
bank1.addAccount(bankAccount1);
bank1.printAccounts();
System.out.println("\nTwo accounts");
BankAccount bankAccount2 = new BankAccount("Sally Ride", 2345);
bankAccount2.adjust(2000.0);
bank1.addAccount(bankAccount2);
bank1.printAccounts();
System.out.println("\nThree accounts");
BankAccount bankAccount3 = new BankAccount("Pat Armstrong", 3456);
bankAccount3.adjust(3000.0);
bank1.addAccount(bankAccount3);
bank1.printAccounts();
System.out.println("\nMonthly Fee");
bank1.monthlyFee(fee);
bank1.printAccounts();
System.out.println("\nErrors:");

if (bank1.getAccount(0).getBalance() != 997.05) {
    errors += 1;
    System.out.println("Balance for account at index 0 does not match $997.05");
}
if (bank1.getAccount(1).getBalance() != 1997.05)
{
    errors += 1;
    System.out.println("Balance for account at index 1 does not match $1997.05");
}
if (bank1.getAccount(2).getBalance() != 2997.05)
{
    errors += 1;
    System.out.println("Balance for account at index 2 does not match $2997.05");
}
if (errors == 0)
    System.out.println("No errors found!!!");
}
}

Any help and guidance is much appreciated. Thank you.

Answer:1

Seems that you forgot to pass the fee parameter to adjust() method. Following code works perfectly fine

 public void monthlyFee(double fee) { //monthly fee for bank accounts
    for(int i = 0; i < bank.length; i++) {
      if(bank[i] != null) {
        System.out.println(bank[i].adjust(fee));
      } //I have tried BankAccount.adjust() and couldn't work, bank[i].adjust() nothing seems to work
    }
  }

Create bank1

One account Joe Mac owns the account 1234 with the balance of $1000.00

Two accounts Joe Mac owns the account 1234 with the balance of $1000.00 Sally Ride owns the account 2345 with the balance of $2000.00

Three accounts Joe Mac owns the account 1234 with the balance of $1000.00 Sally Ride owns the account 2345 with the balance of $2000.00 Pat Armstrong owns the account 3456 with the balance of $3000.00

Monthly Fee 997.05 1997.05 2997.05 Joe Mac owns the account 1234 with the balance of $997.05 Sally Ride owns the account 2345 with the balance of $1997.05 Pat Armstrong owns the account 3456 with the balance of $2997.05

Errors:

No errors found!!!

Answer:2

I am trying to integrate a processing applet in a jsp, with the following code added in the jsp: <!--<applet code="Test1.class" archive="C:\Users\user\Desktop\MyApplet.jar" width="600" height="...

The code works fine. Just looking for information on how to set up my print f and get the desired results. signs more than one print f statement(s): import java.util.Scanner; public class Coupon { ...

This issue is really frustrating me. I am developping a webapp that creates ical files for users. The issue that I am facing, is whenever the ical event repeates weekly or daily or monthly, the start ...

I have an application in which every Sunday, it checks a MySQL database for data from the past week. I am trying to find out how to get the date String for each day of the past week. My obvious ...