Professional Documents
Culture Documents
Ict 3309
Ict 3309
// Constructor
public Employee(int emp_id, double salary, String name, String address,
String department, String email) {
this.emp_id = emp_id;
this.salary = salary;
this.name = name;
this.address = address;
this.department = department;
this.email = email;
}
ii. make shared fields called requiredHours and employeeBonus and initialize them to be enterd by
the user in a static initializer
import java.util.Scanner;
// Static initializer
static {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the required hours: ");
requiredHours = scanner.nextInt();
import java.util.Scanner;
// Static initializer
// ...
// No-argument constructor
public Employee() {
this.name = "Sabonmaaikaci";
this.emp_id = 000;
this.salary = 200000.0;
}
}
v. make a parameterized constructor for initializing all the data members Note:use of constructor
call is mandatory
public class Employee {
private int emp_id;
private double salary;
private String name;
private String address;
private String department;
private String email;
private static int requiredHours;
private static double employeeBonus;
// Parameterized constructor for initializing all data members
public Employee(int emp_id, double salary, String name, String address,
String department, String email) {
this.emp_id = emp_id;
this.salary = salary;
this.name = name;
this.address = address;
this.department = department;
this.email = email;
}
}
Viii. make computeOvertime int hoursWorked that compute overtime payments and add it on top of
salary. the overtime payment is 5000
public class Employee {
private double salary;
private double requiredHours;
ix. make computeEmployeeBonus that computes bonus base on employeeBonus (a percentage) and
add it on top of salary
public class Employee {
private double salary;
private static double employeeBonus;
x. printEmployeeDetails method that prints string representation of an object of Employee class. the
printed string should contain the following each on a separate line emp_id, salary, name
, address , department , email
public class Employee {
private int emp_id;
private String name;
private double salary;
private String address;
private String department;
private String email;
public Employee(int emp_id, double salary, String name, String address, String department,
String email) {
this.emp_id = emp_id;
this.salary = salary;
this.name = name;
this.address = address;
this.department = department;
this.email = email;
}
// ............
}
E. write a java program that declares a jagged array of 5 Employee objects arrays, containing
1,2,3,4,5, objects respectively, read all the required details from the user, compute bonus for each
object, and hence use the printEmployeeDetails() method to computeOvertime(int hoursWorked)
that computes overtime payments and add it on top of salary. The overtime payment is 5000.0 per
hour and print the details of each of the objects
import java.util.Scanner;
public class Employee {
private int emp_id;
private double salary;
private String name;
private String address;
private String department;
private String email;
private static int requiredHours = 40; // Assuming the required working hours per week is 40
private static double employeeBonus = 10; // Assuming the bonus percentage is 10%
// Compute bonus and overtime for each Employee object and print details
for (int i = 0; i < employees.length; i++) {
for (int j = 0; j < employees[i].length; j++) {
System.out.println("\nEmployee Group " + (i + 1) + ", Employee " + (j + 1));
employees[i][j].computeEmployeeBonus();
employees[i][j].computeOvertime(45); // Assuming 45 hours worked for all employees
employees[i][j].printEmployeeDetails();
}
}
scanner.close();
}
}