Você está na página 1de 4

Rules/naming convention’s we need to follow while writing the program

1. Class name every word first letter should be capital. (First Class)
2. Method name first letter should be lower case there after every word first letter should be
upper case. (hello World)
3. For inputting the values, we need to use a method called set Values.
4. For output purpose we need to use a method called get Values.
5. NOTE: For writing the program we have to follow some Hungarian/camel notation.
6. Whenever we are using constants in our program that should be declared as capital letters.
7. Variable names/ Data member names should be in small letter’s.

Like JVM in Java, In apex we have an ARE (Apex Run Time Engine) is a Software program which takes the
responsibility to executive the APEX program the movement we click on run test method ARE looking for
a keyword called testmethod in the program from there its starts the execution.

We cannot write test method within the business class, it must be in test class only.

1) WRITE AN APEX CLASS INPUT EMPLOYEE NO. EMPLOYEE NAME EMPLOYYE BASIC
SALRY, HRA, DA, PF&TAX CALCULATE GROSS SALARY AND NET SALARY.

public class EmpClass {


integer eid,basic_sal,hra,da,pf,Tax,Gs,Ns;
string ename;
// Member Method
// create
public EmpClass()
{
eid=0;
ename='no name';
basic_sal=0;
hra=0;
da=0;
pf=0;
tax=0;
gs=0;
ns=0;
}
public void setvalues (integer eno,string name, integer bs, integer hr, integer d_a,
interger p_f, integer it)
{
Eid=eno;
Ename=name;
Basic_salary=bs;
Hra=hr;
Da=d_a;
Pf=p_f;
Tax=it;
}
Public void gross_sal()
{
Gs=basic_sal+hra+da;
}

Public void net_sal()

{
Ns=gs-(pf=tax);
}

Public void getValues()


{
System.debug (‘the gross salary is ‘ +gs);
System.debug(‘the net salary is ‘ +ns);
}

}
@isTest

Public class EmpClassTest {

Public static testmethod void main()

Empclass obj=new EmpClass();

Obj.setValues(101,’reth’,20000,5000,2000,1000,500);

Obj.gross_sal();

Obj.net_sal();

Obj.getvalues();

}
write an apex class input customer account number, customer name, account balance.
Calculate total balance based on the transaction (i.e. that is deposit or withdraw)
local variable- with in the method

class variables- data members

object variable-

public class bank account {

//data member

Integer ac_no;

string ach_name;

interger ac_bal;

static integer count=0;

//member method;

1.create

Public bankaccount () // default constructor

System.debug(‘I am default constructor’);

Ac_no=0;

Ach_name=’no name’;

Ac_bal=0;

Count++;

Public bank account (integer no, string name, integer bal) // parameterized constructor

System.debug (‘I am a parameterized constructor);

Ac_no=no;

Ach_name = name;

Ac_bal =bal;

Public void set values (integerno, string name, integer bal)


{

Ac_no =no;

Ach_name= name;

Ac_bal =bal;

Public static void get count()

Count++;

System.debug (‘the number of object’s are created’ + count)

Public void get values ()

System.debug(‘acc no’ + ac_no);

System.debug(‘name’ + ach_name);

System.debug(‘balance is’ + ac_bal);

//process

//deposits

Public void deposit (integer amt)

Ac_bal=ac_bal+amt;

//withdraw

Public void checkbalance (integer amt)

Ac_bal

Você também pode gostar