Combining two accounts : <p>This is a homework assignment. I need to consolidate the two accounts (acct2 and acct3) and produce a third one with the same name, different account number and $200. I also have to close the first two accounts. That is not really the issue though. I can get everything to work fine if I do not declare public static Account accountConsolidate(Account acct1, Account acct2) as a static method, and just create an object in the main. This does not work though because I am required to declare this method as static. Also, if I do declare it as static I can get the proper return value in the <code>if(acct1.name.equalsIgnoreCase(acct2.name)  &amp;&amp; acct1.acctNum != acct2.acctNum)</code> if I exclude the
`&amp;&amp; acct1.acctNum != acct2.acctNum
 other wise it will return null ("These two accounts are not able to be consolidated. Please check the criteria again", not sure why. </p>

<p>Any help would be great. Thanks</p>

<pre><code>import java.util.Random;

    public class Account
    {
        private static int numAccounts = 0;
        private double balance;
        private static String name;
        private static double acctNum;
        static Random gen = new Random();

    //-------------------------------------------------
    //Constructor -- initializes balance, owner, and account number
    //-------------------------------------------------
        public Account(double initBal, String owner, double number)
        {
            balance = initBal;
            name = owner;
            acctNum = number;
            numAccounts++;
        }

        public Account(double initBal, String owner)
        {
            balance = initBal;
            name = owner;
            acctNum =  Math.abs(gen.nextDouble());
            numAccounts++;
        }

        public Account(String owner)
        {
            balance = 0;
            name = owner;
            acctNum =  Math.abs(gen.nextDouble());
            numAccounts++;
        }

    //-------------------------------------------------
    // Checks to see if balance is sufficient for withdrawal.
    // If so, decrements balance by amount; if not, prints message.
    //-------------------------------------------------
        public void withdraw(double amount)
        {
            if (balance &gt;= amount)
            {   
                balance -= amount;
            }   
            else
                System.out.println("Insufficient funds");
        }

        public void withdraw(double amount, double fee)
        {
            if (balance &gt;= amount)
                {
                    balance -= amount;
                    balance -= fee; 
                }   
            else
                System.out.println("Insufficient funds");   
        }

    public String getName()
    {
        return name;
    }

    public double getNum()
    {
        return acctNum;
    }

    //-------------------------------------------------
    // Adds deposit amount to balance.
    //-------------------------------------------------
        public void deposit(double amount)
        {
            balance += amount;
        }

    //-------------------------------------------------
    // Returns balance.
    //-------------------------------------------------
        public double getBalance()
        {
            return balance;
        }

    // Static method to keep track of incrementing Account
        public static int getNumAccounts()
        {
            return numAccounts;
        }

    // Close the account
        public void close()
        {
            balance = 0;
            name = "CLOSED";
            numAccounts--;
        }


    // Consolidate accounts
        public static Account accountConsolidate(Account acct1, Account acct2)
        {

            if(acct1.name.equalsIgnoreCase(acct2.name)  &amp;&amp; acct1.acctNum != acct2.acctNum)
            {
                Account Account2 = new Account(0, acct1.name);
                Account2.balance = acct1.getBalance() + acct2.getBalance(); 
                acctNum = Math.abs(gen.nextDouble());

                acct1.close();
                acct2.close();  
                return Account2;

            }
            else
            {
                System.out.println("These two accounts are not able to be consolidated. Please check the criteria again");
                return null;
            }   
        }

    //-------------------------------------------------
    // Returns a string containing the name, account number, and balance.
    //-------------------------------------------------
        public String toString()
        {
            return "Name:" + name +
                "\nAccount Number: " + acctNum +
                "\nBalance: " + balance;
        }
    }

//************************************************************
//TestAccounts1
//A simple program to test the numAccts method of the
//Account class.
//************************************************************
import java.util.Scanner;

    public class TestAccount1
    {
        public static void main(String[] args)
        {
            String name1;
            String name2;
            String name3;

            Scanner scan = new Scanner(System.in);

            System.out.print("Please enter the name for account 1: ");
            name1 = scan.nextLine();
            Account acct1 = new Account (100, name1);
            System.out.println(acct1);
            System.out.println("Now there are " + Account.getNumAccounts() + " accounts");
            System.out.println("");

            System.out.print("Please enter the name for account 2: ");
            name2 = scan.nextLine();
            Account acct2 = new Account (100, name2);
            System.out.println(acct2);
            System.out.println("Now there are " + Account.getNumAccounts() + " accounts");
            System.out.println("");

            System.out.print("Please enter the name for account 3: ");
            name3 = scan.nextLine();
            Account acct3 = new Account (100, name3);
            System.out.println(acct3);
            System.out.println("Now there are " + Account.getNumAccounts() + " accounts");
            System.out.println("");

            acct1.close();
            System.out.println("");
            System.out.println("There are now "  + Account.getNumAccounts() + " accounts");


            System.out.println("Accounts consolidated");
            System.out.println(Account.accountConsolidate(acct2, acct3));
}
}
</code></pre>
