Question

Write a program that reads records containing an employee number and an hourly rate for several...

Write a program that reads records containing an employee number and an hourly rate for
several employees, and stores these in a heap, using employee number as a key. The
program should then allow the user to insert or delete records, and finally use heap sort to
sort the updates list so that the employee numbers are in ascending order, and to display
this sorted list.
You can use the algorithms from the text book.


Example of an employee records will be:
7 10
2 11.50
5 9.50
4 8.50
3 11.50
8 8
1 10.50

Please use Priority Queue as HEAP and hen use Heap Sort to SORT

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Employee implements Comparable{
public int empno;
public double hourlyRate;
public Employee(int empno, double hourlyRate) {
this.empno = empno;
this.hourlyRate = hourlyRate;
}
/**
* @return the empno
*/
public int getEmpno() {
return empno;
}
/**
* @param empno
* the empno to set
*/
public void setEmpno(int empno) {
this.empno = empno;
}
/**
* @return the hourlyRate
*/
public double getHourlyRate() {
return hourlyRate;
}
/**
* @param hourlyRate
* the hourlyRate to set
*/
public void setHourlyRate(double hourlyRate) {
this.hourlyRate = hourlyRate;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Employee [empno=" + empno + ", hourlyRate=" + hourlyRate + "]";
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + empno;
long temp;
temp = Double.doubleToLongBits(hourlyRate);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof Employee))
return false;
Employee other = (Employee) obj;
if (empno != other.empno)
return false;
if (Double.doubleToLongBits(hourlyRate) != Double
.doubleToLongBits(other.hourlyRate))
return false;
return true;
}
@Override
public int compareTo(Object arg0) {
Employee other=(Employee)arg0;
return other.empno-this.empno;
}
public static void main(String[] args) {
List<Employee> employeelist=new ArrayList<Employee>();
Scanner scanner=new Scanner(System.in);
System.out.println("how many records you want to enter");
int no=scanner.nextInt();
for(int i=0;i<no;i++)
{
System.out.println("enter the employeeno");
int no1=scanner.nextInt();
System.out.println("enter the hourlyrate ");
double hourlyrate1=scanner.nextDouble();
Employee emp=new Employee(no1, hourlyrate1);
employeelist.add(emp);
}
System.out.println("enter your choice");
System.out.println("1.insert");
System.out.println("2.deletd");
System.out.println("3.print");
System.out.println("4.quit");
int choice=scanner.nextInt();
switch(choice)
{
case 1: System.out.println("enter the employeeno");
int no2=scanner.nextInt();
System.out.println("enter the hourlyrate ");
double hourlyrate2=scanner.nextDouble();
Employee emp=new Employee(no, hourlyrate2);
employeelist.add(emp);
break;
case 2:System.out.println("enter the employeeno");
int no3=scanner.nextInt();
for(Employee e:employeelist)
{
if(e.empno==no3)
{
employeelist.remove(e);
}
}
break;
case 3:for(Employee e:employeelist)
{
System.out.println(e);
}
break;
case 4:System.exit(0);
break;
default:System.out.println("please select valid choice");
break;
}
}
}

Add a comment
Know the answer?
Add Answer to:
Write a program that reads records containing an employee number and an hourly rate for several...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • DESCRIPTION Implement a program in C++ that generates a specified number of random integers, records them...

    DESCRIPTION Implement a program in C++ that generates a specified number of random integers, records them in three arrays, then sorts the arrays with Insertion Sort, Merge Sort, and Quick Sort, respectively. Augment the three sorting algorithms with counters and report the number of characteristic operations each performs in sorting the (same) random values. INPUT The program reads from the terminal the number of random integers to generate, a seed value for the pseudo-random number generator, and a character that...

  • Write a program in Java to implement the max-priority queue using max-heap data structure. Implement the...

    Write a program in Java to implement the max-priority queue using max-heap data structure. Implement the max-heap data structure using an integer array of 10 cells. (Do not use Java in-built PriorityQueue class.) [In a max-heap, the root node and the intermediate node vales are always greater than their children.] First, take 10 integer values from the user and insert them in the max-priority queue. Then print the elements of the queue. After that, delete two elements from the queue...

  • write this program in Java Problem 5. (30 Points) Write a program that reads employee work...

    write this program in Java Problem 5. (30 Points) Write a program that reads employee work data from a text file employee.txt), and then calculates payroll information based on this file and store them into a new text file called payroll.txt. The employee. txt file contains one line of text for each employee. Each line consists of the following data (delimited by tabs): employee's name, employee's hourly wage rate, hours worked Monday, hours worked Tuesday, hours worked Wednesday, hours worked...

  • Java Programming Write a program to find the number of comparison using binarySearch and the sequentialSearch...

    Java Programming Write a program to find the number of comparison using binarySearch and the sequentialSearch algorithms as follows: Suppose list is an array of 2500 elements. 1. Use a random number generator to fill list; 2. Use a sorting algorithm to sort list; 3. Search list for some items as follows: a) Use the binary search algorithm to search list (please work on SearchSortAlgorithms.java and modify the algorithm to count the number of comparisons) b) Use the sequential search...

  • Write a modularized, menu-driven program to read a file with unknown number of records.

    ==============C++ or java================Write a modularized, menu-driven program to read a file with unknown number of records.Create a class Records to store the following data: first and last name, GPA , an Id number, and an emailInput file has unknown number of records; one record per line in the following order: first and last names, GPA , an Id number, and emailAll fields in the input file are separated by a tab (‘\t’) or a blank space (up to you)No error...

  • PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores...

    PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores integers and and implements a minimum priority queue. (Your program can be "hard coded" for integers - it does not need to use templates, generics, or polymorphism.) Your data structure must always store its internal data as a heap. Your toString function should return a string with the heap values as a comma separated list, also including the size of the heap as well....

  • please use C++ write a program to read a textfile containing a list of books. each...

    please use C++ write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. each line in the file has tile, ..... write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. Each line in...

  • Write a program in Java according to the following specifications: The program reads a text file...

    Write a program in Java according to the following specifications: The program reads a text file with student records (first name, last name and grade on each line). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "print" - prints the student records (first name, last name, grade). "sortfirst" - sorts the student records by first name. "sortlast" - sorts the student records by last name. "sortgrade" - sorts the...

  • Language = c++ Write a program to find the number of comparisons using the binary search...

    Language = c++ Write a program to find the number of comparisons using the binary search and sequential search algorithms as follows: o Suppose list is an array of 1000 elements. o Use a random number generator to fill the list. o Use the function insertOrd to initially insert all the elements in the list. o You may use the following function to fill the list: void fill(orderedArrayListType& list) {       int seed = 47; int multiplier = 2743;                                ...

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT