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

Help me develop a Java system that can track employee information for Googe and

ID: 3888209 • Letter: H

Question

Help me develop a Java system that can track employee information for Googe and Microsoft.The Employee information will consist of Name, Job Title, Birthday. and Organization they work for.

For the Organization that the Employee works for, you also need to track the Organization Name and Number of Emoloyees.

The system must be able to properly compare any two employees against each other to determine if they are the same Person. This means that if you compared two People with the same Name, Birthday, and Organization, the system should think that they are equal to one another. If any of these properties are different, then the two People are not the same Person.

The same rules apply to comparing Organizations to one another. Organizations with the same Organization name are to be thought of as equal, different names means different organizations.

Please use public class Employee

Thank you

Explanation / Answer

// Employee.java

import java.util.Date;

public class Employee extends Person

{

private String name;

private String sex;

private Date birthdate;

private String jobTitle;

private Organization organization;

@Override

public String getName() {

return name;

}

@Override

public String getSex() {

return sex;

}

@Override

public void setName(String p_name) {

if ( null == p_name || p_name.equals("")) {

throw new IllegalArgumentException("This is not a valid name !!");

}

else {

this.name = p_name;

}

}

@Override

public void setSex(String p_sex) {

if ( p_sex.equalsIgnoreCase("male") || p_sex.equalsIgnoreCase("female")) {

this.sex = p_sex;

}

else {

throw new IllegalArgumentException("This is not a valid sex !!");

}

}

@Override

public void setBirthday(Date p_birthdate) {

if ( null == p_birthdate || p_birthdate.equals("")) {

throw new IllegalArgumentException("This is not a valid name !!");

}

else {

this.birthdate = p_birthdate;

}

}

@Override

public Date getBirthday() {

return birthdate;

}

@Override

public boolean equals(Object o) {

boolean retValue = true;

Employee p = (Employee)o;

if ( (! getName().equalsIgnoreCase(p.getName()))

|| (! getSex().equalsIgnoreCase(p.getSex()))

|| (! getBirthday().equals(p.getBirthday()))

|| (! getOrganization().equalsIgnoreCase(p.getOrganization()))

)

{

retValue = false;

}

return retValue;

}

@Override

public String toString() {

String message = super.toString()

+ "Job Title: " + getJobTitle()

+ ", Organization: " + getOrganization();

return message;

}

public String getJobTitle() {

return jobTitle;

}

public void setJobTitle(String p_jobTitle) {

if ( null == p_jobTitle || p_jobTitle.equals("")) {

throw new IllegalArgumentException("This is not a valid job title !!");

}

else {

this.jobTitle = p_jobTitle;

}

}

public String getOrganization() {

return organization.getNameOfOrganization();

}

public void setOrganization(Organization p_organization) {

this.organization = p_organization;

if ( null == p_organization) {

throw new IllegalArgumentException("This is not a valid organization !!");

}

else {

this.organization = p_organization;

}

}

}

================================================================================

//Google.java

public class Google implements Organization

{

private Integer numEmployees;

private String nameOfOrganization;

public Google(String organization) {

this.numEmployees = 666;

this.nameOfOrganization = organization;

}

@Override

public Integer getNumberOfEmployees() {

return numEmployees;

}

@Override

public String getNameOfOrganization() {

return nameOfOrganization;

}

@Override

public void setNumberOfEmployees(Integer numEmployees) {

this.numEmployees = numEmployees;

}

@Override

public void setNameOfOrganization(String nameOfOrganization) {

this.nameOfOrganization = nameOfOrganization;

}

@Override

public boolean equals(Object p_o) {

boolean retValue = true;

Organization org = (Organization)p_o;

if (! getNameOfOrganization().equalsIgnoreCase(org.getNameOfOrganization())) {

retValue = false;

}

return retValue;

}

}

=======================================================================

//Microsoft.java

public class Microsoft implements Organization

{

private Integer numEmployees;

private String nameOfOrganization;

public Microsoft(String organization) {

this.numEmployees = 13;

this.nameOfOrganization = organization;

}

@Override

public Integer getNumberOfEmployees() {

return numEmployees;

}

@Override

public String getNameOfOrganization() {

return nameOfOrganization;

}

@Override

public void setNumberOfEmployees(Integer p_numEmployees) {

this.numEmployees = p_numEmployees;

}

@Override

public void setNameOfOrganization(String p_nameOfOrganization) {

this.nameOfOrganization = p_nameOfOrganization;

}

@Override

public boolean equals(Object p_o) {

boolean retValue = true;

Organization org = (Organization)p_o;

if (! getNameOfOrganization().equalsIgnoreCase(org.getNameOfOrganization())) {

retValue = false;

}

return retValue;

}

}

==============================================================================

//Organization.java

public interface Organization
{
public Integer getNumberOfEmployees();
public String getNameOfOrganization();
public void setNumberOfEmployees(Integer numEmployees);
public void setNameOfOrganization(String nameOfOrganization);
}

=============================================================================

//Person.java

import java.util.Date;

public abstract class Person
{
public abstract String getName();
public abstract String getSex();
public abstract void setName(String name);
public abstract void setSex(String sex);
public abstract void setBirthday(Date birthdate);
public abstract Date getBirthday();
  
@Override
public String toString() {
return "Name: " + getName() + ", Sex: " + getSex() + " ";
}
}

=========================================================================

//Tests.java


import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;


import org.junit.Before;
import org.junit.Test;

public class Tests
{
List<Person> employees = new ArrayList<Person>();
  
@Before
public void init ()
{
Person anEmployee = new Employee();
anEmployee.setName("Trevor Page");
anEmployee.setSex("Male");
Calendar cal = Calendar.getInstance();
cal.set(1983, 0, 1);
anEmployee.setBirthday(cal.getTime());
((Employee)anEmployee).setJobTitle("Sr. Software Engineer");
((Employee)anEmployee).setOrganization(new Google("Google"));
employees.add(anEmployee);
  
anEmployee = new Employee();
anEmployee.setName("Jane Doe");
anEmployee.setSex("Female");
anEmployee.setBirthday(cal.getTime());
((Employee)anEmployee).setJobTitle("Sr. Software Engineer");
((Employee)anEmployee).setOrganization(new Google("Google"));
employees.add(anEmployee);
  
anEmployee = new Employee();
anEmployee.setName("Trevor Page");
anEmployee.setSex("Male");
anEmployee.setBirthday(cal.getTime());
((Employee)anEmployee).setJobTitle("Sr. Software Engineer");
((Employee)anEmployee).setOrganization(new Google("Google"));
employees.add(anEmployee);
  
anEmployee = new Employee();
anEmployee.setName("Trevor Page");
anEmployee.setSex("Male");
anEmployee.setBirthday(cal.getTime());
((Employee)anEmployee).setJobTitle("Sr. Software Engineer");
((Employee)anEmployee).setOrganization(new Microsoft("Microsoft"));
employees.add(anEmployee);
}
  
@Test
public void ensure_toString_method_is_properly_coded()
{
String message = "Name: Trevor Page, Sex: Male" +
" Job Title: Sr. Software Engineer, Organization: Google";

assertThat(employees.get(0).toString(), is(message));
}

@Test
public void ensure_equals_method_is_properly_coded ()
{
assertTrue(employees.get(0).equals(employees.get(2)));
assertFalse(employees.get(0).equals(employees.get(1)));
assertFalse(employees.get(0).equals(employees.get(3)));
assertTrue(employees.get(0).equals(employees.get(0)));
}
}

==========================================================================