Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Wednesday 20 May 2015

constructor and function example in java

class Employee{
double salary,gross,tax=0;
String name,empid;

public Employee(){
gross=0;
tax=0;
salary=0;
name="null";
empid="null";
}
public Employee(String nme,String eid,double sal){
salary=sal;
empid=eid;
name=nme;
}
public double increase_Salary(double percent){
return salary=(salary+((percent*salary)/100));

}
public double calculate_tax(){

if(salary>=100000&& salary<150000){
tax=(10*(salary/100));
}
else if(salary>=150000){
tax=(20*(salary/100));
}
return tax;

}

public double gross_salary(){
if(salary>=100000&& salary<150000){
gross=(salary-(10*(salary/100)));
}
else if(salary>=150000){
gross=salary-(20*(salary/100));
}
return gross;
}

public void display(){
for (int i=1;i<=12;i++){
if(i==1){
System.out.println(i+" "+name+" "+"JAN"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==2){
System.out.println(i+" "+name+" "+"FEB"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==3){
System.out.println(i+" "+name+" "+"MAR"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==4){
System.out.println(i+" "+name+" "+"APR"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==5){
System.out.println(i+" "+name+" "+"MAY"+" "+empid+" "+salary+" "+(calculate_tax()/12)+" "+(gross_salary()/12)+" "+(increase_Salary(20)/12));
}
if(i==6){
System.out.println(i+" "+name+" "+"JUN"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==7){
System.out.println(i+" "+name+" "+"JUL"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==8){
System.out.println(i+" "+name+" "+"AUG"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==9){
System.out.println(i+" "+name+" "+"SEP"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==10){
System.out.println(i+" "+name+" "+"OCT"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==11){
System.out.println(i+" "+name+" "+"NOV"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==12){
System.out.println(i+" "+name+" "+"DEC"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
}
}
public static void main(String[] args){

Employee emp=new Employee("Nikhil Jain","R101",2400000);
emp.display();
}
}

No comments:

Post a Comment