有人可以看看我试图废除并关闭帐户的部分代码吗?这是我想达到的目标:“2.添加方法无效close()来您的账户类此方法应该通过附加关闭当前帐户‘为什么不创建一个对象?
CLOSED’帐户名和白平衡设置, 0.(账户号码应保持不变。)也减少账户总数。“
当我试图编译它时,程序给了我一个关于预期标识符的错误。我错过了什么?
//*******************************************************/
// 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.
//*******************************************************/
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;
}
//----------------------------------------------
// Returns account number.
//----------------------------------------------
public long getAcctNumber()
{
return acctNum;
}
//----------------
//Void and close the accounts
//----------------
public void close(Account)
{
balance = 0;
name = "CLOSE";
acctNum = number;
numAccounts--;
return Account;
}
//----------------------------------------------
// Returns a string containing the name, account number, and balance.
//----------------------------------------------
public String toString()
{
return "Name: " + name +
"\nAccount Number: " + acctNum +
"\nBalance: " + balance;
}
}
编译器是否至少给你一个行号?发布完整的错误消息,它会更有帮助。另外,这功课呢? – FrustratedWithFormsDesigner 2011-04-11 16:14:00
正在做作业吗?它似乎很家庭作业X_X – Neal 2011-04-11 16:14:23
当然它是作业。学校*爱*让学生进行银行账户课程。 :) – 2011-04-11 16:17:11