using methods between classes [SOLVED]
I have 3 classes, the RunAccount, HelpAccount(place for methods) and Account. I am trying to print all the accounts but I am getting this compiler error "printAll(HelpAccount[]) in HelpAccount cannot be applied to (Account[])
HelpAccount.printAll(accountUser);" anybody know how to fix it? Below is my code.
Code:
import java.util.Scanner;
import javax.swing.*;
public class Account {
private int id;
private String firstName;
private String lastName;
private double balance;
private double interestRate;
private static int numberOfAccounts=0;
// constructor
Account(String fn, String ln) {
numberOfAccounts++;
id = numberOfAccounts;
firstName = fn;
lastName = ln;
balance = 0;
interestRate = 0.03;
}
public int getId() {return id;}
public String getFirstName() {return firstName;}
public void setfirstName(String n) { firstName = n;}
public String getLastName() {return lastName;}
public void setLastName(String n) { lastName = n;}
public double getBalance() {return balance;}
public void withdraw (double withdrawAmount)
{
balance = balance - withdrawAmount;
}
public void deposit (double depositAmount)
{
balance = balance + depositAmount;
}
public double getInterestRate() { return interestRate;}
public void setInterestRate (double value) {interestRate = value;}
public static int getNumberOfAccounts() {return numberOfAccounts;};
public String toString ()
{
StringBuffer sb = new StringBuffer();
sb.append("\n======= Begin MyClass object =======\n");
sb.append("\nID: " + id);
sb.append("\nFirst Name: " + firstName);
sb.append("\nLast Name: " + lastName);
sb.append("\nBalance: " + balance);
sb.append("\nInterest Rate: " + interestRate);
sb.append("\n\n======= End MyClass object ========\n");
return (new String(sb));
} // end toString method
} // end class
Code:
import java.util.Scanner;
import javax.swing.JOptionPane;
public class RunAccount
{
public static void main(String[] args)
{
Account[] accountUser = new Account[10];
accountUser[0] = new Account ("George", "Washington");
accountUser[1] = new Account ("Abraham", "Lincoln");
accountUser[2] = new Account ("Barack", "Obama");
accountUser[3] = new Account ("Bill", "Clinton");
HelpAccount.printAll(accountUser);
}
}
Code:
import java.util.Scanner;
import javax.swing.*;
public class HelpAccount
{
public static void printAll (HelpAccount[] print)
{
for (int i=0; i < Account.getNumberOfAccounts(); i++)
{
System.out.println(print[i].toString());
}
}
}