Question

In: Computer Science

Implement an Employee class that includes data fields to hold the Employee’s ID number, first name,...

Implement an Employee class that includes data fields to hold the Employee’s ID number, first name, last name, and hourly pay rate (use of string datatype is not allowed). Create an array of five Employee objects. Input the data in the employee array. Write a searchById() function, that ask the user to enter an employee id, if its present, your program should display the employee record, if it isn’t there, simply print the message ”Employee with this ID doesn’t exist”. The function keeps on asking the user to search again if he wants untill user don’t want to search anymore.

Solutions

Expert Solution

import java.util.*;
class Employee {
    int id;
    String firstname, lastname;
    int hourlypay;

    public Employee(int id, String firstname, String lastname, int hourlypay) {
        this.id = id;
        this.firstname = firstname;
        this.lastname = lastname;
        this.hourlypay = hourlypay;
    }

    public int getId() {
        return this.id;
    }

}



public class Main {
    static void searchbyid(Employee emp[]) {
        Scanner sc = new Scanner(System.in);
            System.out.println("Enter Employee id to search");
            int id = sc.nextInt();
            for(int i = 0;i<2;i++)
            {
            if (emp[i].getId() == id) {
                System.out.println("Search Succesful");
                System.out.println("Displaying Employee Records");
                System.out.println("Firstname:" + emp[i].firstname + " lastname:" + emp[i].lastname + " hourly pay :"
                        + emp[i].hourlypay);

            }           
            }
        sc.close();
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Employee[] emp = new Employee[5];
        for (int i = 0; i < 2; i++) {
            System.out.println("Enter Employee id");
            int id = sc.nextInt();
            System.out.println("Enter Employee Firstname");
            String firstname = sc.next();
            System.out.println("Enter Employee Lastname");
            String lastname = sc.next();
            System.out.println("Enter Employee Hourly Pay");
            int hpay = sc.nextInt();
            emp[i] = new Employee(id, firstname, lastname, hpay);
        }
        searchbyid(emp);
        sc.close();
    }
}

Related Solutions

Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG),...
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG), the course number (for example, 101), the credits (for example, 3), and the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display() method that displays the course data. Create a subclass named LabCourse that adds $50 to the course fee....
make a Pay class that had fields for a single employee's name, ID number, hourly pay,...
make a Pay class that had fields for a single employee's name, ID number, hourly pay, number of hours worked. use appropriate getter and setter methods, and a constructor accepting the employees name, ID number, hourly pay, and number of hours worked as arguments. The Pay class should also have a method that returns the employee's gross pay (gross pay = hourly pay* number of hours worked). In addition include a toString method that prints to screen the employee name,...
C# (Thank you in advance) Create an Employee class with five fields: first name, last name,...
C# (Thank you in advance) Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee and SalaryCalculate...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a doubleannual sales amount. Methods include a constructor that requires values for both data fields, as well as get and set methods for each of the data fields. Write an application named DemoSalesperson that declares an array of 10 Salesperson objects. Set each ID number to 9999 and each sales value to zero. Display the 10 Salesperson objects. public class DemoSalesperson { public static void...
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly...
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name to “XXX”, the apartment number to 0, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy()...
Develop an algorithm to implement an employee list with employee ID ,name designation and department using...
Develop an algorithm to implement an employee list with employee ID ,name designation and department using link list and perform the following operation on the list i)add employee details based on department ii)remove employee details iv)count the number of employee in each department
java/netbeans 1.Design an abstract class Employee that stores: employee name, unique auto-generated id, hire year. Implement...
java/netbeans 1.Design an abstract class Employee that stores: employee name, unique auto-generated id, hire year. Implement any necessary methods in addition to: a.The toString and equals methods. The equals method should NOT compare the id. b.The copy constructor (should copy the same id too) c.An abstract method float getWeeklyCheckAmount() d.Implement the appropriate interface to be able to sort employee names in alphabetical order. Subclasses should NOT be allowed to override this implementation. 2.Design an abstract class HourlyWorker that extends Employee...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
In Chapter 8, you created a Salesperson class with fields for an ID number and sales...
In Chapter 8, you created a Salesperson class with fields for an ID number and sales values. Now, create an application that allows a user to enter values for an array of seven Salesperson objects. Offer the user the choice of displaying the objects in order by either (I)D number or (S)ales value. ----------------------- Salesperson.java public class Salesperson {    private int id;    private double sales;    Salesperson(int idNum, double amt)    {       id = idNum;       sales = amt;    }    public int getId()...
with PHP Create a class called Employee that includes three instance variables—a first name (type String),...
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT