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

1. Implement a generic version of the binary search algorithm in the problem 4.

ID: 3760964 • Letter: 1

Question

1. Implement a generic version of the binary search algorithm in the problem 4.

/**
A class for executing binary searches through an array.
*/
public class BinarySearcher
{
private int[] a;

/**
Constructs a BinarySearcher.
@param anArray a sorted array
*/
public BinarySearcher(int[] anArray)
{
a = anArray;
}

/**
Finds a value in a sorted array, using the binary
search algorithm.
@param v the value to search
@return the index at which the value occurs, or -1
if it does not occur in the array
*/
public int search(int v)
{
int low = 0;
int high = a.length - 1;
while (low <= high)
{
int mid = (low + high) / 2;
int diff = a[mid] - v;

if (diff == 0) // a[mid] == v
return mid;
else if (diff < 0) // a[mid] < v
low = mid + 1;
else
high = mid - 1;
}
return -1;
}
}

2. Write a program that keeps a map in which the keys of the map are objects of class Employee. An employee should have a first name, a last name, and a unique integer ID. For the performance changes and removals, lookup should be by ID. Prompt the user of the program to add or remove employees, to modify the performances, or to print all the performaces. The printout should be sorted by last name. If two employees have the same last name, then use the first name as a tie breaker. If the first names are also identical, then use the integer ID. Supply compatible hashCode and equals methods to the Employee class. Test the hash code by adding the Employee objects to a hash set.

Implementing the following methods:

public static printMenuAndGetChoice()

/**
Adds a student based on user input. Prints an error if a student
is added that already exists in the map.
@param gradeMap the map to associate student object with a grade
@param StudentMap the map to associate student id with a student
*/

/**
Removes a student from the map based on user input
@param gradeMap the map to associate student object with a grade
@param StudentMap the map to associate student id with a student
*/

/**
Modifies an entry based on user input. Prints an error if an invalid student is modified
@param gradeMap the map to associate student object with a grade
@param StudentMap the map to associate student id with a student
*/

   /**
Prints the students and grades
@param gradeMap the map to print
*/

Hint:

Use two maps.

Calculates a hashcode by combining the hashcodes of the instance variables.
@return a hashcode dependant on the instance variables
*/
public int hashCode()
{
final int HASH_MULTIPLIER = 29;
int h = HASH_MULTIPLIER * firstName.hashCode() + lastName.hashCode();
h = HASH_MULTIPLIER * h + ((Integer)id).hashCode();
return h;
}

Explanation / Answer

2) firstly u have to design the database table which stores the data of employee in it.

so the fields of the employee is id/name/address/phno etc.

now we have the destination to which the data is to be stored and all etc.

based on the question we have to write a program that which stores the data within the database from the user or by making some operations

so the program is

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import java.io.*;

import javax.swing.*;

public class manager {

    private JFrame f;

    private JTabbedPane tp;

    private JPanel p1, p2, p3, p4;

    private JButton btn1, btn2;

    private JLabel l1, l2, l3;

    private JTextField t1, t2, t3;

     

    manager()

    {       

        p1 = new JPanel(new GridLayout(4,2));

        p2 = new JPanel(new GridLayout(3,3));

        p3 = new JPanel(new GridLayout(3,3));

        p4 = new JPanel(new GridLayout(3,3));       

         

        btn1 = new JButton("Submit");

        btn2 = new JButton("Reset");

          

        p1.add(l1 = new JLabel("Employee ID"));

        p1.add(t1 = new JTextField(10));

        p1.add(l2 = new JLabel("Employee Name"));

        p1.add(t2 = new JTextField(10));

        p1.add(l3 = new JLabel("Employee Address"));

        p1.add(t3 = new JTextField(10));

        p1.add(btn1);

        p1.add(btn2);

         

        btn1.addActionListener(new ActionListener()

        {

            public void ActionPerformed(ActionEvent ae)

            {

                String s1 = t1.getText();

                String s2 = t2.getText();

                String s3 = t3.getText();

                 

                if(s1=="" || s2=="" || s3=="")

                {

                    return;

                }

                 

                     

                                 

            }

        });

         

        btn2.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e)

            {

                t1.setText("");

                t2.setText("");

                t3.setText("");

            }

        });

         

    }

   

    public void launchFrame()

    {

        JFrame.setDefaultLookAndFeelDecorated(true);

        f = new JFrame("Hello khakhakha!");

         

        tp = new JTabbedPane();

         

        Container c = f.getContentPane();

        c.add(tp);

         

        tp.addTab("Add record", p1);

        tp.addTab("Edit record", p2);

        tp.addTab("Search record", p3);

        tp.addTab("Delete record", p4);

         

        f.pack();

        //f.setSize(400,200);

        f.setVisible(true);

        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

     

    public static void main(String args[]) {

        manager guiWindow = new manager();

        guiWindow.launchFrame();

    }

}

but i am posting just the basic idea and trying for comparing and printing operations once i get i do post it

thank you