Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By quad64bit

Thread: Help! i keep getting error: class, interface, or enum expected

  1. #1
    Azrael is offline Member
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Unhappy Help! i keep getting error: class, interface, or enum expected

    public class BankAccount
    {
    private int balance;
    public BankAccount()
    {
    balance = 10000;
    }
    public int withdraw(int amount)
    {
    balance-=amount;
    return amount;
    }
    public int getBalance()
    {
    return balance;
    }
    }

    import java.util.Scanner;

    class BankAccountTester
    {
    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());
    }
    }

    this i my code, the problem is with the import java.util.scanner

    it gives me the error: class, interface, or enum expected , bnut i dont know how to fix it.

  2. #2
    foulkelore is offline Member
    Join Date
    Dec 2012
    Location
    Des Moines, IA
    Posts
    35
    Rep Power
    0

    Default Re: Help! i keep getting error: class, interface, or enum expected

    Try reformatting you code with the code tags and show us the error your getting. That would help us out.

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Help! i keep getting error: class, interface, or enum expected

    Hello and welcome! Please use [code][/code] tags when posting code so we can easily read it!

    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum

    Java Code:
    java.util.scanner
    Shouldn't it be
    Java Code:
    java.util.Scanner;
    ?
    melvin likes this.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Help! i keep getting error: class, interface, or enum expected

    the problem is with the import java.util.scanner
    All import statements should be before the first class definition.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. class, interface, or enum expected
    By CrazyTofu999 in forum New To Java
    Replies: 4
    Last Post: 01-12-2013, 09:31 PM
  2. Replies: 4
    Last Post: 12-08-2012, 11:56 AM
  3. Replies: 1
    Last Post: 10-03-2012, 10:38 PM
  4. class interface or enum expected Imports java.io.*; error
    By prathamkool in forum New To Java
    Replies: 2
    Last Post: 10-02-2011, 05:53 PM
  5. Replies: 2
    Last Post: 10-02-2010, 03:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •