我使用eclipse查看我的代碼,出現的最常見錯誤是「令牌上的語法錯誤,錯誤的構造(s)」我不確定我在做什麼錯了,但我對Java相當陌生。Java編程的銀行帳戶代碼
我的代碼應該從銀行賬戶中提取一個指定的(用戶輸入)金額,我從$ 10,000開始並設置程序,以便如果提款金額小於0或大於$ 10,000,它將觸發一個斷言錯誤。
class ThreadsUnitProject2 {
public static void main(Sting args [])
// Field member
private int balance;
public void BankAccount()
{
balance = 10000;
}
public int withdraw(int amount)
{
// Subtract requested amount from balance
balance-=amount;
// Return requested amount
return amount;
}
public int getBalance()
{
return balance;
}
import java.util.Scanner;
class BankAccountTester extends BankAccount
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
BankAccount myAccount = new BankAccount();
System.out.println("Balance = " + myAccount.getBalance());
System.out.print("Enter amount to be withdrawn: ");
int amount = scan.nextInt();
assert (amount >= 0 && amount <= myAccount.getBalance()):"You can't withdraw that amount!";
myAccount.withdraw(amount);
System.out.println("Balance = " + myAccount.getBalance());
}
謝謝你的幫助!
將您的'import java.util.Scanner;'移動到文件的頂部。 –
'public static void main(Sting args [])'這需要括號。其他的東西。 –
您應該在提交時修復縮進,以便人們更容易閱讀。另外,你似乎有兩個'main'方法? – AVP