You have to create two classes The first class Employee whic

You have to create two classes. The first class \"Employee\" which included:

The private variables:

first name

last name

id number

Wage

hoursWorked

The hoursWorked variable holds how many total hours the person worked. When the hoursWorked is over 40 hours, it will be considered as over time. Wage holds how much the person makes per hour. After passing the 40 hours, they get 1.5x the wage for each additional hour worked.

The functions:

Constructors

Properties

GetGrossPay: calculate the gross pay for the employee

The second class will be \"EmployeeDemo\" class with the main function. In the main function, read the data from the \"employeeinfo.txt\" file and save the data in the array of (Employee) objects. In the file, the first number is the total number of employees and each employee\'s information. After import the data, display a menu for user to choose:

1 Display all employees

2. Add new employee

3 quit the program

(employeeinfo.txt)

5
John
Wu
A00001
14.50
55
Bob
Ho
A00002
10.50
40
Jenny
Pena
A00003
7.25
65
Sam
Sosa
A00004
12
35
Linda
Jodan
A00005
20.5
46.5

Solution

1. Employee.java

package pkg;

public class Employee {
   private String firstName;
   private String lastName;
   private String idNumber;
   private double wage;
   private double hoursWorked;

   public Employee() {
       super();
   }

   public Employee(String firstName, String lastName, String idNumber,
           double wage, double hoursWorked) {
       super();
       this.firstName = firstName;
       this.lastName = lastName;
       this.idNumber = idNumber;
       this.wage = wage;
       this.hoursWorked = hoursWorked;
   }

   public double getGrossPay() {
       if (hoursWorked > 40) {
           double gp = 40 * wage + (hoursWorked - 40) * wage * 0.5;
           return gp;
       } else {
           return hoursWorked * wage;
       }

   }

   public String getFirstName() {
       return firstName;
   }

   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }

   public String getLastName() {
       return lastName;
   }

   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

   public String getIdNumber() {
       return idNumber;
   }

   public void setIdNumber(String idNumber) {
       this.idNumber = idNumber;
   }

   public double getWage() {
       return wage;
   }

   public void setWage(double wage) {
       this.wage = wage;
   }

   public double getHoursWorked() {
       return hoursWorked;
   }

   public void setHoursWorked(double hoursWorked) {
       this.hoursWorked = hoursWorked;
   }

   @Override
   public String toString() {
       return \"Employee [firstName=\" + firstName + \", lastName=\" + lastName
               + \", idNumber=\" + idNumber + \", wage=\" + wage
               + \", hoursWorked=\" + hoursWorked + \", Gross Pay =\"
               + getGrossPay() + \"]\";
   }

}

------------------------------------

2. EmployeeDemo.java

package pkg;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class EmployeeDemo {
   public static void main(String[] args) throws IOException {
      
       //read input file
       File file1 = new File(\"employeeinfo.txt\");
       FileInputStream in = new FileInputStream(file1);
       BufferedReader br = new BufferedReader(new InputStreamReader(in));
       String strLine;
       int size = 0;
      
       //read size of employees which is first element from input file
       if ((strLine = br.readLine()) != null)
           size = Integer.parseInt(strLine);
      

       Employee[] employees = new Employee[size];
       Employee emp = null;
       for (int i = 0; i < size; i++) {// iterate for the number of employees
           String firstName = br.readLine();
           String lastName = br.readLine();
           String idNumber = br.readLine();
           double wage = Double.parseDouble(br.readLine());
           double hoursWorked = Double.parseDouble(br.readLine());

           emp = new Employee(firstName, lastName, idNumber, wage, hoursWorked);

           employees[i] = emp;
       }
       System.out.println(\"1 Display all employees\");
       System.out.println(\"2. Add new employee\");
       System.out.println(\"3 quit the program\");

       Scanner sc = new Scanner(System.in);
       int choice = sc.nextInt();
       if (choice == 1) {
           displayEmployee(employees);
       } else if (choice == 2) {
           addEmployee();
       } else {
           return;
       }
   }

   private static void addEmployee() {
       //add your code to add employee.
   }

   private static void displayEmployee(Employee[] employees) {
       for (int i = 0; i < employees.length; i++) {
           Employee e = employees[i];
           System.out.println(e);
       }
   }
}

You have to create two classes. The first class \
You have to create two classes. The first class \
You have to create two classes. The first class \
You have to create two classes. The first class \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site