Part 1
Start by designing the Employee class
Employee holds the following private attributes:
NOTE: *NUM_EMP should start off as zero and get updated every time a new Employee is created. The employeeNumber always starts with empl_ followed by the current count of employees and is created automatically every time an Employee object is created.
public String toString() {
// assume you want to print a value that has several decimal places and you only
// want it to print only two decimal places
DecimalFormat df = new DecimalFormat("#.00"); // give it the format
// changes double value to have two decimal places
return "Value is : " + df.format(value);
}
Details
EmployeeDemo:
Read in data using a Scanner object to create five Employee
objects. Print the employees and then using a call to the Employee
class, print out the number of Employees.
Input
Data for five employees in the following format:
{last name} {first name} {dept} {job} {salary} (repeat for five
total employees)
Sample Input:
Brown Sue HumanResources Manager 65000 Smith Bob Marketing Accounts
38000 Kyle John HumanResources Administrator 29000 Brown Lynn Sales
OnlineSalesRep 32000 Byrne Sara Sales Manager 65000
Output
Employee: Sue Brown (empl_1): Manager, HumanResources ($65000.00) Employee: Bob Smith (empl_2): Accounts, Marketing ($38000.00) Employee: John Kyle (empl_3): Administrator, HumanResources ($29000.00) Employee: Lynn Brown (empl_4): OnlineSalesRep, Sales ($32000.00) Employee: Sara Byrne (empl_5): Manager, Sales ($65000.00) Number of employees: 5
Part 2
Now design the EmployeeRecord class
The EmployeeRecord class uses an ArrayList that holds employees, and has an attribute that holds the company name (both are private attributes):
public class EmployeeRecord {
private ArrayList<Employee> list;
private String name;
// rest of the code
}
The EmployeeRecord class should have the following methods:
Note: You can add other methods that you think are helpful, but remember to comment them!
Part 3
In this part, you will be implementing a hefty demo for your EmployeeClass.
Note: You may assume that the strings read in for Employee and EmployeeDemoare a single word.
Details
Input
Sample Input:
AcmeToys Brown Sue HumanResources Manager 65000 Smith Bob Marketing
Accounts 38000 Kyle John HumanResources Administrator 29000 Brown
Lynn Sales OnlineSalesRep 32000 Byrne Sara Sales Manager 65000
Brown empl_1 Sales Manager
Output
Sample Output:
AcmeToys Total Employees: 5 Employee: Lynn Brown (empl_4): OnlineSalesRep, Sales ($32000.00) Employee: Sue Brown (empl_1): Manager, HumanResources ($65000.00) Employee: Sara Byrne (empl_5): Manager, Sales ($65000.00) Employee: John Kyle (empl_3): Administrator, HumanResources ($29000.00) Employee: Bob Smith (empl_2): Accounts, Marketing ($38000.00) Employees with the last name of Brown: [Employee: Lynn Brown (empl_4): OnlineSalesRep, Sales ($32000.00), Employee: Sue Brown (empl_1): Manager, HumanResources ($65000.00)] Employees with employee number empl_1: Employee: Sue Brown (empl_1): Manager, HumanResources ($65000.00) Employees in Sales: [Employee: Lynn Brown (empl_4): OnlineSalesRep, Sales ($32000.00), Employee: Sara Byrne (empl_5): Manager, Sales ($65000.00)] Employees who are a Manager: [Employee: Sue Brown (empl_1): Manager, HumanResources ($65000.00), Employee: Sara Byrne (empl_5): Manager, Sales ($65000.00)] Employee/s who earn the most: [Employee: Sue Brown (empl_1): Manager, HumanResources ($65000.00), Employee: Sara Byrne (empl_5): Manager, Sales ($65000.00)] After deleting the employee: AcmeToys Total Employees: 4 Employee: Lynn Brown (empl_4): OnlineSalesRep, Sales ($32000.00) Employee: Sara Byrne (empl_5): Manager, Sales ($65000.00) Employee: John Kyle (empl_3): Administrator, HumanResources ($29000.00) Employee: Bob Smith (empl_2): Accounts, Marketing ($38000.00) After deleting the employee: AcmeToys Total Employees: 3 Employee: Lynn Brown (empl_4): OnlineSalesRep, Sales ($32000.00) Employee: Sara Byrne (empl_5): Manager, Sales ($65000.00) Employee: Bob Smith (empl_2):
Solution
package student;
import java.text.DecimalFormat;
public class Employee {
private static int NUM_EMP = 0;
private String firstName;
private String lastName;
private int employeeNumber;
private double salary;
private String jobTitle;
private String department;
public Employee(String firstName, String lastName, double salary, String jobTitle, String department) {
this.firstName = firstName;
this.lastName = lastName;
this.salary = salary;
this.jobTitle = jobTitle;
this.department = department;
employeeNumber = ++NUM_EMP;
}
public static int getCount() {
return NUM_EMP;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getEmployeeNumber() {
return employeeNumber;
}
public void setEmployeeNumber(int employeeNumber) {
this.employeeNumber = employeeNumber;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String getJobTitle() {
return jobTitle;
}
public void setJobTitle(String jobTitle) {
this.jobTitle = jobTitle;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public String toString() {
DecimalFormat df = new DecimalFormat("#.00");
return "Employee : " + firstName + " " + lastName +
" (empl_" + employeeNumber + "): " +
jobTitle +
", " + department + "($" + df.format(salary) + ")";
}
}
=======================================================================================
package student;
import java.util.ArrayList;
public class EmployeeRecord {
private ArrayList<Employee> list;
private String name;
public EmployeeRecord(String name) {
this.name = name;
list = new ArrayList<>();
}
// add employee such that they are sorted lexicographically
public void addEmployee(Employee emp) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getFirstName().compareTo(emp.getFirstName()) > 0) {
list.add(i, emp);
return;
}
}
list.add(emp);
}
public void printEmployees() {
for (Employee emp : list) {
System.out.println(emp);
}
}
// returns the employee with same id
public Employee getEmployee(int employeeId) {
for (Employee emp : list) {
if (emp.getEmployeeNumber() == employeeId) {
return emp;
}
}
return null;
}
// returns the employee list with same last name
public ArrayList<Employee> getEmployeeByLastName(String lName) {
ArrayList<Employee> lastNames = new ArrayList<>();
for (Employee emp : list) {
if (emp.getLastName().equalsIgnoreCase(lName)) {
lastNames.add(emp);
}
}
return lastNames;
}
//// returns the employee with same job titles
public ArrayList<Employee> getEmployeeByTitle(String title) {
ArrayList<Employee> titles = new ArrayList<>();
for (Employee emp : list) {
if (emp.getJobTitle().equalsIgnoreCase(title)) {
titles.add(emp);
}
}
return titles;
}
// returns the employee with same dept name
public ArrayList<Employee> getEmployeeByDepartment(String dept) {
ArrayList<Employee> depts = new ArrayList<>();
for (Employee emp : list) {
if (emp.getDepartment().equalsIgnoreCase(dept)) {
depts.add(emp);
}
}
return depts;
}
// returns the employee with max salary
public Employee getEmployeeEarnsMost() {
double salary = 0;
Employee employee = null;
for (Employee emp : list) {
if (salary < emp.getSalary()) {
employee = emp;
salary = emp.getEmployeeNumber();
}
}
return employee;
}
public ArrayList<Employee> getList() {
return list;
}
public void setList(ArrayList<Employee> list) {
this.list = list;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Company Name: " + getName() + ", Total Employees: " + list.size();
}
// driver method
public static void main(String[] args) {
Employee e1 = new Employee("Sue", "Brown", 65000, "Manager", "Human Resources");
Employee e2 = new Employee("Bob", "Smith", 38000, "Accounts", "Marketing");
Employee e3 = new Employee("John", "Kyle", 29000, "Administrator", "Human Resources");
Employee e4 = new Employee("Lynn", "Brown", 32000, "Online Sales Rep", "Sales");
Employee e5 = new Employee("Sara", "Nyrne", 65000, "Manager", "Sales");
EmployeeRecord record = new EmployeeRecord("Microsoft");
record.addEmployee(e1);
record.addEmployee(e2);
record.addEmployee(e3);
record.addEmployee(e4);
record.addEmployee(e5);
record.printEmployees();
System.out.println("Number of employees: " + Employee.getCount());
}
}
According to HomeworkLib rules I am allowed to answer only 2 subquestions . Feel free to reach out regarding any queries . Thank you .
Part 1 Start by designing the Employee class Employee holds the following private attributes: a count...
Write a program that implements a rudimentary name-finder. It should start out by filling up a name ArrayList with Name objects. Then it should ask the user if he/she wants to find a particular name. Then it should search for the name in the name ArrayList and return the names information if the name is found. Here is a suggested UML class diagram: Implement Name filltheblackbook method by adding anonymous objects representing these four names: First Name Last Name Address...
Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string SSN; The Employee class has ▪ a no-arg constructor (a no-arg contructor is a contructor with an empty parameter list): In this no-arg constructor, use “unknown” to initialize all private attributes. ▪ a constructor with parameters for each of the attributes ▪ getter and setter methods for each of the private attributes ▪ a method getFullName() that returns the last name, followed by a...
Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...
Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...
In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...
Create a class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyEmployee that inherits from the Employee class. HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the...
DatabaseFilter Design a DatabaseFilter class that will manage the file 1/O (input/output) of an employee ArrayList object. For a Database Filter class to actually store an ArrayList object, it must know the file to which the list must be read from or written to. Note: It is expected that you may have more methods within your class design than requested in the specifications described below. However, your class should support at a minimum the following data and operations: encapsulated data...
Following is the EmployeeTester class, which creates object of the class Employee and calls the methods of that object. The EmployeeTester class is written to test another class: Employee. You are required to implement the class Employee by: declaring its instance variables: name, age, salary. implementing its constructor. implementing its methods: getEmployeeName(), getEmployeeAge(), getEmployeeSalary(), setEmployeeAge(int empAge), setEmployeeSalary(double empSalary) public class EmployeeTester { public static void main(String args[]) { // Construct an object Employee employeeOne = new Employee("Ahmad Abdullah"); //...
Create a Java application, that support the following: Create an Employee class, which holds following information: Employee First Name Employee Last Name Employee Phone Number Employee Address Employee id Employee Title Employee salary Create an application that uses the Employee class Constructors –Getters and setters A minimum of 3 constructors including default constructor equals() method Helper methods toString() method Create an array of 5 Employee objects Use a Scanner to read in 5 employee information Change 2 employees information (3-items...
In the Employee class, add an implementation for the calculatePension() method declared in the interface. Calculate the pension to date as the equivalent of a monthly salary for every year in service. 4) Print the calculated pension for all employees. ************** I added the interface and I implemented the interface with Employee class but, I don't know how can i call the method in main class ************ import java.io.*; public class ManagerTest { public static void main(String[] args) { InputStreamReader...