Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class named Employee that has the following data fields and constructors

ID: 3828454 • Letter: W

Question

Write a class named Employee that has the following data fields and constructors A private String data field named name A private String data field named idNumber A private String data field named department A no-arg constructor A constructor that accepts the following values as arguments and assigns them to the appropriate fields: employee's name, employee's ID number, and department. Also write appropriate mutator methods that stores values in these fields and accessor methods that return the values in these fields. Write another class named EmployeeTest, in main method, ask the user to enter the employee's name, ID number, and department, create an instance of the Employee class, assign the data to its attributes, and display the information, notice that you have to call the accessor methods (getters in the Employee class) to get the info and display using println or printf. (Check the sample output below) You can name your program Employeejava and EmployeeTestjava

Explanation / Answer

Find the below code.

Employee.java

public class Employee {

   private String name;
   private String idNumber;
   private String department;

//no args constructor
   public Employee() {}
  

//constructor with arguments
   public Employee(String name, String idNumber, String department) {
       this.name = name;
       this.idNumber = idNumber;
       this.department = department;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public String getIdNumber() {
       return idNumber;
   }

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

   public String getDepartment() {
       return department;
   }

   public void setDepartment(String department) {
       this.department = department;
   }
        
}

EmployeeTest.java

import java.util.Scanner;

public class EmployeeTest {
   public static void main(String[] args) {
       Employee emp = new Employee();
       System.out.println("Enter the Employee Name");
       Scanner s = new Scanner(System.in);
       String name = s.nextLine();
       System.out.println("Enter the Employee ID number");
       String id = s.nextLine();
       System.out.println("Enter the Employee Department");
       String dept = s.nextLine();
       //To set the value into employee objects
       emp.setName(name);
       emp.setDepartment(dept);
       emp.setIdNumber(id);
       System.out.println("Here is the data that you provided");
       System.out.println("Employee Name: " + emp.getName());
       System.out.println("Employee ID: " + emp.getIdNumber());
       System.out.println("Employee Department: " + emp.getDepartment());
      
   }
}

OUTPUT:

Enter the Employee Name
bags
Enter the Employee ID number
591908
Enter the Employee Department
IT
Here is the data that you provided
Employee Name: bags
Employee ID: 591908
Employee Department: IT

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote