It\'s an entry basedata so it doesn\'t matter how many of employees do we have s
ID: 3804020 • Letter: I
Question
It's an entry basedata so it doesn't matter how many of employees do we have since it's a database and we could build on it
The full Output from chioce 1 to choice 7 in the entry
You are going to build a database that an employer can use to keep track of their employees. You will need a way to represent a single employee (name, id number, salary) and a way to store an unknown number of employees. You will build the capability to addremove employees from the database and provide some other functionality described below. Assignment Create an Outlab5 project and paste this into a Driver. You won't need to change the Driver. Here are descriptions of the methods you need o add Employee. This method reads in a name and salary to represent a new employee. The employee id number is just the number that employe was to join the company I e. The first employee e added, has id number 1, the second id number 2. and so on. If an employee ends up leaving the company, employee numbers stay the same and new employees are still given the next number. E.g. If employee 1 leaves. employee 2 stays employee 2 o remove Employee. This method removes an employee from the database based on the employee id number passed. Le. If employee 123 is to be removed, find the employee with id number 123 and remove them. If that employee does not exist, prunt an eIT message or o printByld. This method will print out all the employees in the database by order of their id numbers starting with employee 1. If some employee (e.g. ployee number 7 s no longer in the database, just skip that number o payIncrease. Give each employee a pay increase of X% where X is the input parameter. o getPayrollCost. eturn the total amount of salary of all the employees in the database Here is some sample output Rules You are not allowed to use AmayLists or any other built in java data structures beyond plain array You are not allowed to use any sort of build in sorting functions. You don't need them Figure out how to do it yourself You are allowed to use the compareTo method in the String clas You will lose all the points for a method if you break these rules for that method Hints 1. This ass. There may be methods classes you want that I did not tell you about. Think about what tools you need to efficiently implement your design Think very carefully about how to represent employees in your system. There are multiple ways to do it. Some are good ideas and some are bad. Run your idea through me if you want. You could just add employees to your database in the order they are inputed by the user, or you could insert them into specific parts of your database. Think about it: If you add in the order they are recieved. that is easy but printing them alphabetically is hard. If you add them to the specific spot to ensure they are stored in alphabetical order. adding is not a easy. but printing them is super easy You do not need to do any fancy sorting. If you mention "bubble sort" or anything else you found onlin you are making it more complicated than you need to. Read about the method compareTo in the String class for seeung if one String comes before or after another in lexicographical order 6. Your solution needs to be general enough to handle not knowing how many employees will be added or even how many Database instances will be created. The Driver only creates one Database instance. but it could just as easily create multiplExplanation / Answer
Database.java
public class Database{
Node head;
int ids=1;
class Node
{
String name;
int Id;
double salary;
Node next;
Node(String n, double s,int id) {
name = n;
salary = s;
Id = id;
next = null;
}
}
public void addEmployee(String n, double s)
{
Node new_node = new Node(n,s,ids);
if (head == null)
{
head = new Node(n,s,ids);
ids++;
return;
}
ids++;
/* 4. This new node is going to be the last node, so
make next of it as null */
new_node.next = null;
/* 5. Else traverse till the last node */
Node last = head;
while (last.next != null)
last = last.next;
/* 6. Change the next of last node */
last.next = new_node;
return;
}
void removeEmployee(int key)
{
// Store head node
Node temp = head, prev = null;
// If head node itself holds the key to be deleted
if (temp != null && temp.Id == key)
{
head = temp.next; // Changed head
return;
}
// Search for the key to be deleted, keep track of the
// previous node as we need to change temp.next
while (temp != null && temp.Id != key)
{
prev = temp;
temp = temp.next;
}
// If key was not present in linked list
if (temp == null) return;
// Unlink the node from linked list
prev.next = temp.next;
}
void payIncrease(double incr){
Node temp = head;
while (temp != null)
{
temp.salary*=(1+incr);
temp = temp.next;
}
}
double getPayrollCost(){
Node temp = head;
double payroallCost = 0.0;
while (temp != null)
{
payroallCost+=temp.salary;
temp = temp.next;
}
return payroallCost;
}
void printAlphabetically(){
Node temp = head;
int s=0;
while (temp != null)
{
s++;
temp = temp.next;
}
int k=0;
Node temps[] = new Node[s];
temp = head;
while(temp != null){
temps[k++]=temp;
temp = temp.next;
}
for(k=0;k<s;k++){
for(int j=k+1;j<(s-1);j++){
if(temps[k].name.compareTo(temps[j].name) > 0 ){
temp = temps[k];
temps[k] = temps[j];
temps[j] = temp;
}
}
}
for(k=0;k<s;k++){
System.out.println(temps[k].name+", "+(temps[k].Id) +", "+temps[k].salary);
}
}
void printById(){
Node temp = head;
int s=0;
while (temp != null)
{
s++;
temp = temp.next;
}
int k=0;
Node temps[] = new Node[s];
temp = head;
while(temp != null){
temps[k++]=temp;
temp = temp.next;
}
for(k=0;k<s;k++){
for(int j=k+1;j<(s-1);j++){
if(temps[k].Id > temps[j].Id ){
temp = temps[k];
temps[k] = temps[j];
temps[j] = temp;
}
}
}
for(k=0;k<s;k++){
System.out.println((temps[k].Id) +", "+temps[k].name+", "+temps[k].salary);
}
}
}
Result:
Employee Management System
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 1
Name? > Peter
Salary? > 1000
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 1
Name? > Jack
Salary? > 200
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 1
Name? > Rock
Salary? > 324
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 1
Name? > Mike
Salary? > 345
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 1
Name? > John
Salary? > 233
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 3
Jack, 2, 200.0
Mike, 4, 345.0
Peter, 1, 1000.0
Rock, 3, 324.0
John, 5, 233.0
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 4
1, Peter, 1000.0
2, Jack, 200.0
3, Rock, 324.0
4, Mike, 345.0
5, John, 233.0
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 2
ID Number? > 3
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 4
1, Peter, 1000.0
2, Jack, 200.0
4, Mike, 345.0
5, John, 233.0
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 6
1778.0
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 5
Percent Increase (e.g. .02)? > 0.03
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 4
1, Peter, 1030.0
2, Jack, 206.0
4, Mike, 355.35
5, John, 239.99
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 6
1831.34
1. Add Employee.
2. Remove Employee.
3. Print Alphabetically.
4. Print By ID Number.
5. Issue Pay Increase.
6. Get Payroll Cost.
7. Quit.
Please enter your choice > 7
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.