Question

In: Computer Science

Write an iterative method printHighEarners() to print all high earner employees. Method printHighEarners()is in the class...

Write an iterative method printHighEarners() to print all high earner employees. Method printHighEarners()is in the class LinkedList. LinkedList has private instance variable list of Node type. Class Node is private inner class inside of class LinkedList, and has public instance variables: data and next of Employee and Node type, respectively. In addition, class Node has constructor and toString method. See LinkedList class bellow on the right. Class Employee has getters for all data, method String toString() that returns string of all employee data, and method boolean isHighEarner() that returns true if employee's salary is above average, and false otherwise.

public void printHighEarners ()

{

}

public class LinkedList

{

      private Node list;

      public LinkedList()

      {

          list = null;

      }

      public Node getList()

      {

          return list;

      }

      . . .//other methods

      // insert method printHighEarners here

      // insert method lowestPaidEmployeeRec

      private class Node

      {

          public Employee data;

          public Node next;

          public Node(Employee emp)

          {

              data = emp;

              next = null;

          }

          public String toString()

          {

            return data.toString();

          }

      }     

}                                                                                                                                                                                                                                                                               

  

                  

Solutions

Expert Solution

Here's the updated code including the method which is asked:

class LinkedList
{
    private Node list;
    public LinkedList()
        {
                list = null;
        }

        public Node getList()
        {
                return list;
        }

        // method to print to high earners
        public void printHighEarners() 
        {

                // temp node for traversing the list
                Node trav = list;
                while (trav != null) 
                {
                        // check if current Employee is a high earner then print it else continue
                        if (trav.data.isHighEarner())
                                System.out.println(trav.data.toString());
                                
                        trav = trav.next;
                }
        }

        private class Node
        {
                public Employee data;
                public Node next;

                public Node(Employee emp)
                {
                        data = emp;
                        next = null;
                }

                public String toString()
                {
                        return data.toString();
                }

        }     

}

Added comments for the method printHighEarners() for better understanding. Do refer them.

Hope it helps, for any further doubt, feel free to reach out!

Consider giving a thumbs up if it helped! :)

Cheers!


Related Solutions

Write an iterative method printHighEarners() to print all high earner employees. Method printHighEarners()is in the class...
Write an iterative method printHighEarners() to print all high earner employees. Method printHighEarners()is in the class LinkedList. LinkedList has private instance variable list of Node type. Class Node is private inner class inside of class LinkedList, and has public instance variables: data and next of Employee and Node type, respectively. In addition, class Node has constructor and toString method. See LinkedList class bellow on the right. Class Employee has getters for all data, method String toString() that returns string of...
Write an iterative method countHighEarners() to return the number of nodes storing an high earner employee....
Write an iterative method countHighEarners() to return the number of nodes storing an high earner employee. Method countHighEarners()is in the class LinkedList that has private instance variable list of Node type. Class Node is private inner class inside of class LinkedList, and has public instance variables: data and next of Employee and Node type, respectively. In addition, class Node has constructor and toString method. See LinkedList class bellow on the right. Class Employee has getters for all data, method String...
3. [Method 1] In the Main class, write a static void method to print the following...
3. [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. 4. [Method 2] In the...
Complete the // TODO sections in the EasyRental class. Create a method that implements an iterative...
Complete the // TODO sections in the EasyRental class. Create a method that implements an iterative sort that sorts the vehicle rentals by color in ascending order (smallest to largest) Create a method to binary search for a vehicle based on a color, that should return the index where the vehicle was found or -1 You are comparing Strings in an object not integers. Ex. If the input is: brown red white blue black -1 the output is: Enter the...
Use LinkedList build-in class (java.util.LinkedList) to write a Java program that has: A. Method to print...
Use LinkedList build-in class (java.util.LinkedList) to write a Java program that has: A. Method to print all elements of a linked list in order. B. Method to print all elements of a linked list in reverse order. C. Method to print all elements of a linked list in order starting from specific position. D. Method to join two linked lists into the first list in the parameters. E. Method to clone a linked list. The copy list has to be...
class Loops{ public void printNumbers(int low, int high){ // using a for loop, print all numbers...
class Loops{ public void printNumbers(int low, int high){ // using a for loop, print all numbers from low to high for(int i = low; i <= high; i++){ System.out.println(i); } } public int sumOfNumbers(int n){ // using a for loop, calculate and return the sum of first n numbers // i.e n = 5, answer = 5+4+3+2+1 = 15 int sum = 0; for(int i = 1; i <= n; i++){ sum += i; } return sum; } public void...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version)...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version) The recursive ternarySearch method returns true or false depending if the element was found or not. The ternarySearch method works in a similar manner to a binary search except it uses two mid values that “divide” the array into three portions. So, it needs to consider three recursive scenarios: See sample run: Accounts are: [0] 5658845 [1] 8080152 [2] 1005231 [3] 4520125 [4] 4562555...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version)...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version) The recursive ternarySearch method returns true or false depending if the element was found or not. The ternarySearch method works in a similar manner to a binary search except it uses two mid values that “divide” the array into three portions. So, it needs to consider three recursive scenarios: See sample run: Accounts are: [0] 5658845 [1] 8080152 [2] 1005231 [3] 4520125 [4] 4562555...
We have created an ArrayList of Person class. write a method called push that pushes all...
We have created an ArrayList of Person class. write a method called push that pushes all the people with the even length last name to the end of the ArrayList Content of the ArrayList before push [alex Bus, Mary Phillips, Nik Lambard, Rose Rodd, Esa khan, Jose Martinex, Nik Patte] content of the ArrayList after the push method [alex Bus, Nik Lambard, Nik Patte, Mary Phillips, Rose Rodd, Esa khan, Jose Martinex] import java.util.*; class Person { private String name;...
PLEASE USE MEHODES (Print part of the string) Write a method with the following header that...
PLEASE USE MEHODES (Print part of the string) Write a method with the following header that returns a partial string: public static String getPartOfString(int n, String firstOrLast, String inWord) Write a test program that uses this method to display the first or last number of characters of a string provided by the user. The program should output an error if the number requested is larger than the string. SAMPLE RUN #1: java PartOfString Enter a string: abracadabra↵ Enter the number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT