You need to sign in to do that
Don't have an account?
Donnie 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());
}
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());
}
include other code in a another method inside above class or other class
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?
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);
}
}