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
harshadeepthi kharshadeepthi k 

Hi Everyone, Please help me with the error - it says unexpected token em when I'm trying to execute & even the date function throws an error in code saying needs a return type:date.

public class emp {
integer A;

 
    public  emp (string Name,  String Qualification,Integer Age, Date DOB ,Integer Address, Integer pSalary){
        for (A = 0; A>= 1000 ; A++ ) {
            system.debug(A);
        String D = 'Department IT' ;
        system.debug(D);
        }
            
    }
            
    

            public void ComSal() {
                    Integer vSalary = 15000;
                    abc(vSalary);
                    System.assertEquals(vSalary , 1);
                    system.debug(vSalary);
    }
               public void abc (Integer vSalary){
                    Integer C;
                    integer pSalary;
                    double hCommission;
                    C = vSalary;
                    system.debug(c);
                    if (pSalary >=15000){
                             hCommission = pSalary * .25 ;
                        system.debug(hCommission); }
        
    }

   /* public void date today(){
        date.today();
        return date ;
    }*/
}

 

------

emp em = new emp('Harsh', ' BSc Micro' , 21, 1997-05-26,1234,16000);
em.abc(16000);

DivyanshD SinghDivyanshD Singh

replace public  emp to public void emp, 

and public void date today() to public Date today()

Hope this helps.

harshadeepthi kharshadeepthi k

Hello Divyansh,

Thank you for the reply,

I've changed the constructor emp to method , but when I'm trying to execute it it is throwing an error saying unexpected token em ;

& the date statement isn't working.

DivyanshD SinghDivyanshD Singh
Hello Harshadeepthi,
Can you paste you full code here,and also mention the lines where you are getting this error.
Thanks
harshadeepthi kharshadeepthi k

Hi Divyansh,

I've solved  the Unexpected Token issue in the debug by placing inverted commas to Date arguement, now while I'm executing the code  I'm getting another error(Execute Anonymous Error) saying -   Line: 261, Column: 14
Constructor not defined: [homework].<Constructor>(String, String, Integer, String, Integer, Integer)

The following is my code - 

 

public class homework {
public string gName = '', gQualification ='';
public integer gAge = 0, gAddress = 0, gSalary = 0;
public date gDOB =null;

 
    public  homework (string Name,  String Qualification,Integer Age, Date DOB ,Integer Address, Integer pSalary){
        integer A;
        for (A = 0; A>= 1000 ; A++ ) {
            system.debug(A);
        String D = 'Department IT' ;
        system.debug(D);
        }
            gName = Name;
            gQualification = Qualification;
            gAge = Age;
            gDOB = DOB;
            gAddress = Address;
            gSalary = pSalary;
    }
            
    

            public void ComSal() {
                    Integer vSalary = 15000;
                    abc(vSalary);
                    System.assertEquals(vSalary , 1);
                    system.debug(vSalary);
    }
               public void abc (Integer vSalary){
                    Integer C;
                    integer pSalary;
                    double hCommission;
                    C = vSalary;
                    system.debug(c);
                    if (pSalary >=15000){
                             hCommission = pSalary * .25 ;
                        system.debug(hCommission); }
        
    }

   /* public void date today(){
        date.today();
        return date ;
    }*/
}

 

------

//executable code -

homework h = new homework('hd' , 'dfg', 21, '1997-05-26', 5678,16000);
h.abc(16000);

DivyanshD SinghDivyanshD Singh
Hello Harshadeepthi,
you need to specify the data type each time you declare a variable,like below,
public class homework {

 String gName = '' ;
String gQualification ='';

 Integer gAge = 0;
Integer gAddress = 0;
Integer  gSalary = 0;
 date gDOB =null;


Arey you calling this class from a vf Page?
If not this should work.
Thanks
harshadeepthi kharshadeepthi k

Hi Divyansh,

I've debuged all the errors, thank you for the help. Following is the code -

 

public class homework {
public string gName = '', gQualification ='';
public integer gAge = 0, gAddress = 0, gSalary = 0 , gAutoNumber = 0;
public date gDOB =null;

 
    public  homework (string pName,  String pQualification,Integer pAge, Date pDOB ,integer pAutoNumber ,Integer pAddress, Integer pSalary){
        /*integer A;
        for (A = 1; A>= 1000 ; A++ ) {
            system.debug(A);
        
        }*/
            gName = pName;
            gQualification = pQualification;
            gAge = pAge;
            gDOB = pDOB;
            gAutoNumber = pAutoNumber;
            gAddress = pAddress;
            gSalary = pSalary;
system.debug(gQualification ); 
system.debug(gAge);
system.debug(gDOB);
system.debug(gAutoNumber);
system.debug(gAddress);
system.debug(gSalary);
system.debug(gName);
 

system.debug('DOJ : ' + date.today() );
String D = 'Department IT' ;
        system.debug(D);
Double Commission = pSalary * .25 ;
    system.debug(Commission);

    }
            
    

            public void ComSal() {
                    Integer vSalary = 15000;
                    abc(vSalary);
                    system.debug(vSalary);
    }
               public void abc (Integer vSalary){
                    Integer C;
                    //integer gSalary;
                    double hCommission;
                    C = vSalary;
                    system.debug(C);
                    if (gSalary >=15000){
                             hCommission = gSalary * .25 ;
                        system.debug(hCommission); }
        
    }
}

 

----

//execution code -

homework h = new homework('harsh' , 'micro', 22, date.valueOf('1997-05-26'),5, 56789,19000);
h.abc(19000);

 

Thanks & Regards,

Harsha Deepthi K.

DivyanshD SinghDivyanshD Singh
Glad to hear you solved the issue.
Seems your homework is done now . lol :P
Happy coding.
Thanks & Regards,
Divyansh Singh