v> Write a Java programme (named EmployeePay.java) that calculates the weekly
pay for each of your employees based on the total number of hours they have
worked in a week using the following guidelines.
•
All employees are paid a regular hourly rate of some amount. (Determine
that amount in Ghana cedis)
•
Indicate the number of regular working hours for all employees in a week
•
Some employees occasionally work overtime and are supposed to be paid for
the hours they have worked overtime. (Determine the overtime hourly rate in
Ghana cedis. Note: Overtime hourly rate should be more than the regular
hourly rate).
•
Employees can however only do a maximum of 2 overtime hours each day
package employee;
import java.util.Scanner;
public class Employee {
private String name;
private int id;
public Employee(String n, int i){
name = n;
id = i;
}
public String getName(){
return name;
}
public int getId(){
return id;
}
public static void main(String[] args) {
System.out.println("How many employees do want to process their details");
Scanner input = new Scanner(System.in);
int number = input.nextInt();
Payment [] emp = new Payment[number];
System.out.println("Enter the details for 10 employees");
for(int i=0; i<number; i++){
System.out.println("Employee "+(i+1));
System.out.println("Enter employee id");
int id = input.nextInt();
System.out.println("Enter employee name");
String name = input.next();
System.out.println("Enter employee salary");
float sal = input.nextFloat();
emp[i] = new Payment(sal, name, id);
}
System.out.println("\nThe employees details are:\n\n");
for(int i=0; i<number; i++){
System.out.println("Employee "+(i+1));
emp[i].display();
}
}
}
class Payment extends Employee{
private float salary;
Payment(float sal, String n, int i){
super(n,i);
salary = sal;
}
void display(){
System.out.printf("Employee Name: \t%s\n Employee ID:\t%d"
+ "\n Employee Salary %f ", getName(),getId(),getSalary());
}
public float getSalary(){
return salary;
}
}
Comments
Leave a comment