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

The goal of this project is to create and manipulate an indexed list of employee

ID: 3864259 • Letter: T

Question

The goal of this project is to create and manipulate an indexed list of employees. the class employee has two data members: the name and phone number of an employee, and four member functions: set Name (), display Name (), set Phone () and display Phone (). the template class index List is posted on UR Courses (see lecture notes). in the class index List, include only the member functions that you need for this project. Write a driver program that will create an object, called my Employee List, which is an indexed list of N employees. the driver will also sort the employee list using the selection sort algorithm and display the sorted list. the selection sorting algorithm should be implemented in the template class index List. A sample run follows. List of type "Employee" Enter number of employees: 3 Enter next name: Sam Enter next phone number: 555-0000 Enter next name: Brenda Enter next phone number: 888-0000 Enter next name: Matt Enter next phone number: 333-0000

Explanation / Answer

// Employee.java

public class Employee {

private String name;

private String phoneNumber;

public String getName() {

   return name;

}

public void setName(String name) {

   this.name = name;

}

public String getPhoneNumber() {

   return phoneNumber;

}

public void setPhoneNumber(String phoneNumber) {

   this.phoneNumber = phoneNumber;

}

@Override

public String toString() {

   return "Employee [name=" + name + ", phoneNumber=" + phoneNumber + "]";

}

public Employee(String name, String phoneNumber) {

   super();

   this.name = name;

   this.phoneNumber = phoneNumber;

}

}

public class IndexList {

   Employee emp[];// array of Emp

   int numberOfEmp;

   // The template class indexList is posted on UR Course (see lecture notes).

   // This information you have not given on question on portal. So I am

   // assuming this class.

   static int idx = 0;

   public IndexList(int numberOfEmp) {

       super();

       this.numberOfEmp = numberOfEmp;

       emp = new Employee[numberOfEmp];

   }

   public void selectionSort() {

       for (int i = 0; i < numberOfEmp; i++) {

           int min = i;

           String min_name = emp[i].getName();

           for (int j = i + 1; j < numberOfEmp; j++) {

               if (emp[j].getName().compareTo(min_name) < 1) {

                   min_name = emp[j].getName();

                   min = j;

               }

           }

           if (min != i) { // swap

               Employee temp = emp[i];

               emp[i] = emp[min];

               emp[min] = temp;

           }

       }

   }

   public void printEmpList() {

       for (int i = 0; i < numberOfEmp; i++)

           System.out.println(emp[i]);

   }

   public void dataToList(String name, String phoneNumber) {

       emp[idx] = new Employee(name, phoneNumber);

       idx++;

   }

}

//Driver.java

import java.util.Scanner;

public class Driver {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       System.out.println("Enter number of Employee");

       int numOfEmp = sc.nextInt();

       if (numOfEmp < 1) {

           sc.close();

           return;

       }

       IndexList myEmployeeList = new IndexList(numOfEmp);

       for (int i = 0; i < numOfEmp; i++) {

           System.out.print("Enter next name: ");

           String name = sc.next();

           System.out.println();

           System.out.print("Enter next phone number: ");

           String phoneNumber = sc.next();

           myEmployeeList.dataToList(name, phoneNumber);

       }

       myEmployeeList.selectionSort();// based on name

       myEmployeeList.printEmpList();

       sc.close();

   }

}

//========================result========

Enter number of Employee

3

Enter next name: saurabh

Enter next phone number: 4343

Enter next name: ankit

Enter next phone number: 43

Enter next name: rita

Enter next phone number: 432

Employee [name=ankit, phoneNumber=43]

Employee [name=rita, phoneNumber=432]

Employee [name=saurabh, phoneNumber=4343]

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