//*******************************************************
// Account.java
//
// A bank account class with methods to deposit to, withdraw from,
// change the name on, and get a String representation
// of the account.
//*******************************************************
import java.util.Random;
public class Account
{
private double balance;
private String name;
private long acctNum;
//----------------------------------------------
//Constructor -- initializes balance, owner, and account number
//----------------------------------------------
public Account(double initBal, String owner, long number)
{
balance = initBal;
name = owner;
acctNum = number;
}
//----------------------------------------------
// 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 >= amount)
balance -= amount;
else
System.out.println("Insufficient funds");
}
//----------------
//Track how many accounts
//----------------
private static int numAccounts=0;
{
numAccounts++;
}
public static int getNumAccounts()
{
return numAccounts;
}
//----------------------------------------------
// Adds deposit amount to balance.
//----------------------------------------------
public void deposit(double amount)
{
balance += amount;
}
//----------------------------------------------
// Returns balance.
//----------------------------------------------
public double getBalance()
{
return balance;
}
// Get name of account
public String getName()
{
return name;
}
//----------------------------------------------
// Returns account number.
//----------------------------------------------
public long getAcctNumber()
{
return acctNum;
}
//----------------
//Void and close the accounts
//----------------
public void close()
{
balance = 0;
name += "CLOSE";
numAccounts--;
}
//----------------
//Consolidating accounts
//----------------
public static Account consolidate(Account acct1,Account acct2)
{ Account newAccount=null;
if((acct1.getName()).equals(acct2.getName()))
if(acct1.getAcctNumber()!=acct2.getAcctNumber())
{newAccount= new Account(acct1.getBalance()+acct2.getBalance(),String owner);
Random generator = new Random();
acctNum= generator.nextInt();
acct1.close();
acct2.close();
}
else
System.out.println("Not allow,same account number");
else
System.out.println("Can't use other people account");
return newAccount;
}
//----------------------------------------------
// Returns a string containing the name, account number, and balance.
//----------------------------------------------
public String toString()
{
return "Name: " + name +
"\nAccount Number: " + acctNum +
"\nBalance: " + balance;
}
}
Пожалуйста, посмотрите раздел // консолидации.То, что я пытаюсь сделать, это объединить acct1 и acct2 в одну новую учетную запись, с ограничениями, которые acct1 и acct2 должны иметь одинаковые имена, номера учетных записей acct1 и acct2 должны отличаться друг от друга, и если онивстретились, создать новую учетную запись с новым балансом из двух старых учетных записей, сохранить то же имя, а также случайным образом создать новый номер учетной записи.Чего-то не хватает в моем коде?Это не скомпилируется.Это ошибки, которые я получил
Account.java:95: ')' expected
{newAccount= new Account(acct1.getBalance()+acct2.getBalance(),String owner);
^
Account.java:95: illegal start of expression
{newAccount= new Account(acct1.getBalance()+acct2.getBalance(),String owner);
^