function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Donnie IsaacDonnie Isaac 

Unexpected syntax: missing EOF

Hi all,

I'm relatively new to Apex and I have been studying the Apex for non-coders. I have run into a snag in that the code I am including below runs in Execute Anonymous on Force.com IDE, but won't run in the main window so I can't save it to the server. I am using windows 8, Eclipse 4.4, Force.com IDE 33.0 and have no problems with anything else. On line 10 it gives me: unexpected syntax: missing EOF at 'BankAcct'
I haven't been able to fix the error (I tried deleting the curly brace, adding one, moving things around, nothing worked) and can't spot any syntax errors otherwise (since it runs in Execute Anon,) so anyone got ideas? Thanks!

public class BankAcct {
     private integer balance = 0;
     public string acctName;
       public string accttype;
       public void makeDeposit (integer deposit){
           balance = balance + deposit;
        }
    public integer getBalance() {
          return balance;
    }

BankAcct chkAcct = new BankAcct();
chkAcct.accttype = 'Checking';
chkAcct.acctName = 'D.Castillo-Chk ';
chkAcct.makeDeposit(150);
BankAcct savAcct = new BankAcct();
savAcct.accttype = 'Savings';
savAcct.acctName = 'D.Castillo–Sav';
savAcct.makeDeposit(220);
List <BankAcct> bankAccts = new List<BankAcct>();
System.debug('The BankAcct List has ' + bankAccts.size() + ' bank  accounts.');
bankAccts.add(chkAcct);
bankAccts.add(savAcct);
System.debug('The BankAcct List has ' + bankAccts.size() + ' bank    accounts.');
System.debug('Here is the list: ' + bankAccts);
For (BankAcct  tempacct:bankAccts)

 system.debug(tempacct.acctName + ' is a ' + tempacct.accttype +' account with a balance of $'+ tempacct.getBalance());
 }

 
surasura
you cant have code outside your class , your class ends at line 11
surasura
you class is only valid upto below shown point
 
public class BankAcct {
     private integer balance = 0;
     public string acctName;
       public string accttype;
       public void makeDeposit (integer deposit){
           balance = balance + deposit;
        }
    public integer getBalance() {
          return balance;
    }
}

include other code in a another method inside above class or other class
Harpreet On CloudHarpreet On Cloud
As pointed out by sura, your code ends at the curly brases. Whatever code after that has to be part of a method either in the same class or in some other class. From the code, it seems that the BankAcct class is a data class and hence the following code has to be part of another class that uses your data class.
BankAcct chkAcct = new BankAcct();
chkAcct.accttype = 'Checking';
chkAcct.acctName = 'D.Castillo-Chk ';
chkAcct.makeDeposit(150);
BankAcct savAcct = new BankAcct();
savAcct.accttype = 'Savings';
savAcct.acctName = 'D.Castillo–Sav';
savAcct.makeDeposit(220);
List <BankAcct> bankAccts = new List<BankAcct>();
System.debug('The BankAcct List has ' + bankAccts.size() + ' bank  accounts.');
bankAccts.add(chkAcct);
bankAccts.add(savAcct);
System.debug('The BankAcct List has ' + bankAccts.size() + ' bank    accounts.');
System.debug('Here is the list: ' + bankAccts);
For (BankAcct  tempacct:bankAccts)
{ 
 system.debug(tempacct.acctName + ' is a ' + tempacct.accttype +' account with a balance of $'+ tempacct.getBalance());
 }

 
Donnie IsaacDonnie Isaac
Dear HarpreetOnCloud, Thanks so much for responding. I get that the code ends at line 11. Since I'm new, could you suggest a possible solution to how to include the other code in that class - or even another class- ( obviously within a method?) That would be very helpful to teach me. Thanks, Donnie
Donnie IsaacDonnie Isaac
Thank you for taking the time to respond. Very kind of you. Donnie
Stephanie BoggsStephanie Boggs
Hey, I am currently doing the same exercise, and ran across the same type of issue. I ran the chkAcct code as an Execute Anonymous, and it removed the EOF error, but it now doesn't recognize 'BankAcct'. 

BankAcct.cls =
public class BankAcct {
    private integer balance=0;
    public string acctName;
    public string accttype;
    public void makeDeposit (integer deposit){
         balance = balance + deposit;
    }
    public integer getBalance(){
        return balance;
    }
}

Execute Anonymous = 
BankAcct chkAcct = new BankAcct();
    chkAcct.accttype = 'Checking';
    chkAcct.acctName = 'D.Castillo-Chk';
    chkAcct.makeDeposit(150);
    System.debug(chkAcct);

Results & User Debug Logs = 
Compile error at line 1 column 24
Invalid type: BankAcct

Did you ever have any luck getting this to work?
Stephanie BoggsStephanie Boggs
I figured it out; I was working offline. :) 
kathy tangkathy tang
Hi Stephanie, would you pls explain in more details about how you fixed the problem? i am new here, and except for the problem you mentioned as above. i also encountered a problem that "unexpected token . and unexpected token =" just beside the line chkAcct.acctType = 'checking';
Vikrum JaitlyVikrum Jaitly
Please help me out to find the solution of this error - Missing '<EOF>' at '@' from the following program:

public class TemperatureConverterTest {
 // Takes a Fahrenheit temperature and returns the Celsius equivalent.
    public static Decimal FahrenheitToCelsius(Decimal fh) {
        Decimal cs = (fh - 32) * 5/9;
        return cs.setScale(2);
    }
}
@isTest private class TemperatureConverterTest {
    @isTest static void testWarmTemp() {
        Decimal celsius = TemperatureConverter.FahrenheitToCelsius(70);
        System.assertEquals(21.11,celsius);
    }
    
    @isTest static void testFreezingPoint() {
        Decimal celsius = TemperatureConverter.FahrenheitToCelsius(32);
        System.assertEquals(0,celsius);
    }
    @isTest static void testBoilingPoint() {
        Decimal celsius = TemperatureConverter.FahrenheitToCelsius(212);        
        System.assertEquals(100,celsius,'Boiling point temperature is not expected.');
    } 
    
    @isTest static void testNegativeTemp() {
        Decimal celsius = TemperatureConverter.FahrenheitToCelsius(-10);
        System.assertEquals(-23.33,celsius);
    }
}