Computer Program
Computer Program
Computer Program
1. (a) In class Employee created in Assignment 1 add static instance field emp_count.
Use emp_count for getting emp_id in proper sequence. Also include appropriate
(c) Write methods to compare two Employees based upon their salary and return object
having higher salary.
Code:
// For Executive
public Employee(String name, int salary, String designation, String COMPANY){
this.name = name;
this.emp_id = emp_count++;
this.salary = salary;
this.designation = designation;
this.COMPANY = COMPANY;
}
// For Freshers
public Employee(String name){
this.name = name;
emp_id = emp_count++;
salary = 20000;
designation = "Developer";
}
System.out.println("\nFreshers \n");
employee[0].display();
System.out.println("\nExecutive \n");
employee[1].display();
System.out.println("\nTemporary Member \n");
employee[2].display();
//Assignment 2 part c
System.out.println("\nPerson having high salary is = " +
Employee.compareSalary(employee[0], employee[1]));
// Assignment 2 part d
employee[0].salary_increase(10, 12000);
employee[1].salary_increase(20);
System.out.println("\nEmployee [0] = " + employee[0].salary);
System.out.println("Employee [1] = " + employee[1].salary);
//Assignment 2
System.out.println("\nNo. of employee in the organisation = " + emp_count);
//Assignment 2: part d
public void salary_increase(int p, int b){
salary = salary + salary * p/100 + b;
}
public void salary_increase(int p){
salary = salary + salary * p/100;
}
Output:
For final keyword error output:
Code:
int emp_id;
int salary;
String designation;
static int emp_count = 0;
final String COMPANY = "GOOGLE";
// For Executive
public Employee(String name, int salary, String designation, String COMPANY){
this.name = name;
this.emp_id = emp_count++; this.salary = salary; this.designation = designation;
this.COMPANY = COMPANY;
}
public static void main(String[] args){
}
2. Write a java program to illustrate - “Java uses pass by value”
Code:
class Animal {
String name;
Output: