Why is this an illegal start on an expression? public Account consolidate(Account accnt1, Account accnt2)
In my if statement It says name has private access in account. What does that mean and how do i fix it?
if((accnt1.name).equals(accnt2.name))

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

public class TestConsolidation
{
    public static void main(String[] args)
    {
        
        //Account consolidate- the sum of acct1 and acct2
  public static Account consolidate(Account accnt1, Account accnt2)
  {
      Account newAccount = null;
      if((accnt1.name).equals(accnt2.name))
      {
          if(accnt1.acctNum!=accnt2.acctNum)
          {
              String Name = accnt2.name;
              double balances = accnt1.balance + accnt2.balance;
              //Account accountSum;
              //int accountSum;
              //accountSum.balance = account1.getBalance() + account2.getBalance();
              //Consolidate acct1 and acct2 like newAccount = (name, balance of 2 accts, acctnum(random));
		accnt1.close();
		accnt2.close();
                numAccounts++;
          }}


      return newAccount;

  }

    }
}

You can't declare methods inside other methods. Get consolidate() out of main().

How would I do that? And what about the second question?

How would I do that?

Well, move it outside main(). Cut-paste the entire thing outside of the braces that delimit the main() method.

Well, move it outside main(). Cut-paste the entire thing outside of the braces that delimit the main() method.

Ok. Any idea about this part?
In my if statement It says name has private access in account. What does that mean and how do i fix it?
if((accnt1.name).equals(accnt2.name))

If you have declared it private then you will need to use a public getter method to get the name. Same for balance.

If you have declared it private then you will need to use a public getter method to get the name. Same for balance.

I don't even see the word private. Any ideas why it thinks it is private?

If you haven't specified a modifier and they are in a different package, they are private.

Use a public method getName() to get the name - don't access the variable directly.

If you haven't specified a modifier and they are in a different package, they are private.

Use a public method getName() to get the name - don't access the variable directly.

When you say modifier I assume you mean public, private, and protected? And not sure what you mean by package. Could you explain what you mean by package please.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.