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

\"you must to demonstrate that the Main routine will run on a Binary Search Tree

ID: 3903122 • Letter: #

Question

"you must to demonstrate that the Main routine will run on a Binary Search Tree" (IN JAVA)

===================================================

Consider the following list of employees at a company. We wish to place this data into a set of objects of the class “Employee”.

Emp_ID

Last_Name

Salary

101

Harris

$53,000

110

Smith

$107,000

112

Jones

$63,500

114

Smith

$42,500

118

Wilson

$89,000

123

Abrams

$92,000

In order to easily manage the list, we need to create a linked list that orders the employees by Emp_ID. The class “LinkedElement” has been provided. You are given the challenge to create your own “LinkedList” class meeting the interface supplied on Blackboard.

Create a ListMain class with a main routine to:

1) Places the data into six separate Employee objects and creates a linked list to organize the objects.

2) Prints out the last name of the employee with the highest salary.

3) Removes Employee 101.

4) Tells whether there is an employee with Emp_ID 123 and gives the last name if there is.

5) Tells whether there is an employee with Emp_ID 101 and gives the last name if there is.

6) Print out the last names of the all of the current employees.

===============================================

Emp_ID

Last_Name

Salary

101

Harris

$53,000

110

Smith

$107,000

112

Jones

$63,500

114

Smith

$42,500

118

Wilson

$89,000

123

Abrams

$92,000

Explanation / Answer

Implemented Source Code:-
---------------------------------
package com.bel;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
class LinkedElement
{
String empID;
String lastName;
double salary;
LinkedElement next;
LinkedElement(String empID,String lastName,double salary)
{
this.empID = empID;
this.lastName=lastName;
this.salary=salary;
next = null;
}
}
public class Employee
{
private String empID;
private String lastName;
private double salary;
LinkedElement head;
public void insert(String empID,String lastName,double salary)
{
LinkedElement new_Node = new LinkedElement(empID,lastName,salary);
new_Node.next = head;
head = new_Node;
head.next=null;
}
public void printList()
{
LinkedElement temp2 = head;
while (temp2 != null)
{
System.out.print(temp2.empID+" "+temp2.lastName+" "+temp2.salary);
temp2 = temp2.next;
}
}
public void PrintLastName()
{
LinkedElement temp = head;
while (temp != null)
{
System.out.print(temp.lastName);
temp = temp.next;
}
}
public Employee(String empID, String name, double pay)
{
this.empID = empID;
lastName = name;
salary = pay;
}
public String getID()
{
return empID;
}
public String getName()
{
return lastName;
}
public double getSalary()
{
return salary;
}
public boolean search_Empid(String id)
{
LinkedElement temp = head;
while (temp != null)
{
if(id==temp.empID)
{
System.out.print(temp.lastName);
return true;
}
temp = temp.next;
}
return false;  
}
public void PrintHighestSalary()
{
double max=0;
LinkedElement temp = head;
while (temp != null)
{
if(max<temp.salary)
{
max=temp.salary;
}
temp = temp.next;
}
System.out.println(" The Highest Salary of Employee is:"+max);
}
public static void main(String[] args) throws FileNotFoundException
{
Employee obj = null;
boolean status;
File Empdetails = new File ("F:\Workspace_Luna\Empdata.txt");
Scanner scanner = new Scanner(Empdetails);
String emp_id,Name;
double salary;
System.out.println("--------------------------------");
while(scanner.hasNextLine())
{
emp_id=scanner.next();
Name = scanner.next();
salary= scanner.nextDouble();
obj=new Employee(emp_id,Name,salary);
obj.insert(emp_id, Name, salary);
System.out.println(Name+" "+emp_id+" "+salary);
}
scanner.close();
System.out.println("All Employee Records are:");
obj.printList();
obj.PrintHighestSalary();
status=obj.search_Empid("123");
if(status==false)
System.out.println("the Employee id 123 Not found");
status=obj.search_Empid("101");
if(status==false)
System.out.println("the Employee id 101 Not found");
System.out.println("The Last Names of Current Employees");
obj.PrintLastName();
}
}

input file:-
------------
101 Harris 53000
110 Smith 107000
112 Jones 63500
114 Smith 42500
118 Wilson 89000
123 Abrams 92000

Here I have Used File class to read the data and store into Employee Objects instead of creating 6 different Objects.

I hope you are Like my Answer!