Assignment 2 is at the bottom of the picture.

Make the following enhancements to Assignment 2 1. Clean up assignment 2 2. Create a new constructor which does not accept th

Please enter Enter Employee 1 employees name Jane Enter Employee 1 employees salary 100000″ src=”https://files.transtutors.com/cdn/qimg/b430a91cd80d4a28b67d567c95e68456.jpg” aria-describedby=”j7l”>$951.92 Please enter Enter. Employee 3 employees name Jack Enter Employee 3 employees salary 110000 Enter Employee 3 employ

package e2;

import java.util.Scanner;

public class Employee {

private String name;
private int ID;
private int salary;
private Gender gender;
private static int totalEmployee = 0;
private static int totalSalary = 0;

public static Employee createEmployee() {

Scanner scan = new Scanner(System.in);

System.out.print(“Enter your name: “);
String s = scan.nextLine();
System.out.print(“Enter your employee ID: “);
int ID = scan.nextInt();
scan.nextLine();
System.out.print(“Enter your annual salary: “);
int salary = Integer.parseInt(scan.nextLine());
totalSalary += salary;
System.out.print(“Enter Gender:(M/F): “);
String gender = scan.nextLine();
do {
if (gender.equalsIgnoreCase(“m”) || gender.equalsIgnoreCase(“male”)) {

gender = “Male”;
break;
} else if (gender.equalsIgnoreCase(“f”) || gender.equalsIgnoreCase(“female”)) {
gender = “Female”;
break;
} else {

System.out.println(“Invalid gender! Enter again: “);
gender = scan.nextLine();
}
} while (!gender.equalsIgnoreCase(“Male”) || !gender.equalsIgnoreCase(“Female”));
return new Employee(s, ID, salary, Gender.valueOf(gender));

}

public Employee(String name, int iD, int salary, Gender gender) {
super();
this.name = name;
ID = iD;
this.salary = salary;
this.gender = gender;
totalEmployee++;//to count the number of employee
}

//getter and setter
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getID() {
return ID;
}

public void setID(int iD) {
ID = iD;
}

public int getSalary() {
return salary;
}

public void setSalary(int salary) {
this.salary = salary;
}

public Gender getGender() {
return gender;
}

public void setGender(Gender gender) {
this.gender = gender;
}

@Override
public String toString() {
return “Employee [name=” + name + “, Gender= ” + gender + “, ID=” + ID + “, salary=” + salary + “]”;
}

public static int getTotalEmployee() {
return totalEmployee;
}

public static int getTotalSalary() {
return totalSalary;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ID;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + salary;
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Employee other = (Employee) obj;
if (ID != other.ID)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (salary != other.salary)
return false;
return true;
}

}

package e2;

import java.util.Scanner;

public class Employee {

private String name;
private int ID;
private int salary;
private Gender gender;
private static int totalEmployee = 0;
private static int totalSalary = 0;

public static Employee createEmployee() {

Scanner scan = new Scanner(System.in);

System.out.print(“Enter your name: “);
String s = scan.nextLine();
System.out.print(“Enter your employee ID: “);
int ID = scan.nextInt();
scan.nextLine();
System.out.print(“Enter your annual salary: “);
int salary = Integer.parseInt(scan.nextLine());
totalSalary += salary;
System.out.print(“Enter Gender:(M/F): “);
String gender = scan.nextLine();
do {
if (gender.equalsIgnoreCase(“m”) || gender.equalsIgnoreCase(“male”)) {

gender = “Male”;
break;
} else if (gender.equalsIgnoreCase(“f”) || gender.equalsIgnoreCase(“female”)) {
gender = “Female”;
break;
} else {

System.out.println(“Invalid gender! Enter again: “);
gender = scan.nextLine();
}
} while (!gender.equalsIgnoreCase(“Male”) || !gender.equalsIgnoreCase(“Female”));
return new Employee(s, ID, salary, Gender.valueOf(gender));

}

public Employee(String name, int iD, int salary, Gender gender) {
super();
this.name = name;
ID = iD;
this.salary = salary;
this.gender = gender;
totalEmployee++;//to count the number of employee
}

//getter and setter
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getID() {
return ID;
}

public void setID(int iD) {
ID = iD;
}

public int getSalary() {
return salary;
}

public void setSalary(int salary) {
this.salary = salary;
}

public Gender getGender() {
return gender;
}

public void setGender(Gender gender) {
this.gender = gender;
}

@Override
public String toString() {
return “Employee [name=” + name + “, Gender= ” + gender + “, ID=” + ID + “, salary=” + salary + “]”;
}

public static int getTotalEmployee() {
return totalEmployee;
}

public static int getTotalSalary() {
return totalSalary;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ID;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + salary;
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Employee other = (Employee) obj;
if (ID != other.ID)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (salary != other.salary)
return false;
return true;
}

}

Make the following enhancements to Assignment 2 1. Clean up assignment 2 2. Create a new constructor which does not accept the employee ID as an argument. Instead, the employee I will be assigned based on the static variable which counts the number of employees. The first employee will have the ID 1 etc. 3. Your program will first prompt the user for how many employees will be entered. Then it will prompt for those employees using the new constructor you created in part 1.++ 4. Print off the total and average salary for all the employees 5. In the test program, prompt the user for an employee ID and print that employee. What if they enter an ID greater than the total number of employees? Or a negative value? Enter the number of employees > Please enter Enter Employee 1 employee’s name Jane Enter Employee 1 employee’s salary 100000 Enter Employee 1 employee’s department (sales, tech or accounting) Please enter weekly hours for Jane 45 $2,283.65 Please enter Enter Employee 2 employee’s name Mike Enter Employee 2 employee’s salary 90000 Enter Employee 2 employee’s department (sales, tech or accounting) Enter Employee 2 employee’s department (sales, tech or accounting) Please enter weekly hours for Mike 22 $951.92 Please enter Enter. Employee 3 employee’s name Jack Enter Employee 3 employee’s salary 110000 Enter Employee 3 employee’s department (sales, tech or accounting) Please enter weekly hours for Jack Invalid number Please enter weekly hours for Jack 70 $4,495.19 There are 3 employees They make a total of $300,000.00 a year The average salary is $100,000.00 a year Enter the ID of the employee you want > Employee Name: Jane Employee ID: 1 salary: $100,000.00 department: sales



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *