I am using eclipse to look at my code and the most common error that comes up is "Syntax error on token(s), misplaced construct(s)" I'm not sure what I am doing wrong, but I am fairly new to Java.
My code is supposed to withdraw an indicated (user-input) amount from a bank account, I started off with $10,000 and set up the program so that if the withdrawal amount is less than 0 or greater than $10,000 it will trigger an assertion error.
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());
}
Thank you for all of your help!