I think i got most of this done but im stuck on one thing right now:
this is what i have so far:
public class Employee { private String name; private static double annualSalary; private String yearHired; private String socialSecurityNumber; private String GregorianCalender; public Employee(){ super(); name = "no name"; annualSalary = 0.0; yearHired = "January 1, 1900"; socialSecurityNumber = "999999999"; } public Employee(String name, double salary, GregorianCalender year, String ssn){ annualSalary = salary; yearHired = GregorianCalender; socialSecurityNumber = ssn; } public Employee(Employee emp){ annualSalary = emp.getAnnualSalary(); //yearHired = emp.getYearHired(); socialSecurityNumber = emp.getSocialSecurityNumber(); } public double getAnnualSalary(){ return annualSalary; } public GregorianCalender getYearHired(GregorianCalender date){ return date; } public String getSocialSecurityNumber(){ return socialSecurityNumber; } public void setAnnualSalary(double salary){ annualSalary = salary; } public void setYearHired(GregorianCalender date){ yearHired = GregorianCalender; } public void setSocialSecurityNumber(String ssn){ socialSecurityNumber = ssn; } public String toString(){ return("Name:" + name + "/n Year Hired: " + yearHired + "/n Annual Salary: " + annualSalary + "/nSocial Security Number: " + socialSecurityNumber); } public boolean equals(Object obj){ } }
thats one class I have one more other class and a main class
public class Person { //instance field for the name of the Person private String name; /** * Default constructor */ public Person() { name= "no name"; } /** * Constructor that set the name to what is passed in * @param n The name of the Person you are creating */ public Person(String n) { name = n; } /** * Returns the name of the person * @return The name of the person */ public String getName() { return name; } /** * Set the Person's name to name that is passed in * @param n Name that you want to set the Person's name to. */ public void setName(String n){ name = n; } /** * overrides default toString() method, that returns the Person in string form * @return The Person as a string */ @Override public String toString() { return("Person's name is " + getName()); } }
and this is the main class that im using to test
import java.util.GregorianCalendar; public class TestEmployee { public static void main(String[] args) { Employee e1 = new Employee(); Employee e2 = new Employee("Bob Smith", 45000.5, new GregorianCalendar(2009, 0, 1), "123456789"); Employee e3 = new Employee(e2); System.out.println(e1.toString()); System.out.println(e2.toString()); System.out.println(e3.toString()); if (e2.equals(e3)) System.out.println(new StringBuilder().append(e2.getName()).append (" is the same as ").append (e3.getName()).toString()); else System.out.println(new StringBuilder().append(e2.getName()).append (" is NOT the same as ").append (e3.getName()).toString()); System.out.println(); e3.setName("Test Person"); e3.setSocialSecurityNumber("134256987"); e3.setAnnualSalary(65000.63); e3.setYearHired(new GregorianCalendar(2009, 9, 15)); System.out.println(e1.toString()); System.out.println(e2.toString()); System.out.println(e3.toString()); if (e2.equals(e3)) System.out.println(new StringBuilder().append(e2.getName()).append (" is the same as ").append (e3.getName()).toString()); else System.out.println(new StringBuilder().append(e2.getName()).append (" is NOT the same as ").append (e3.getName()).toString()); } }
this is that its asking me to do for this part
public boolean equals (Object obj)public boolean equals(Object obj){ }
Method that returns true if the invoking object and the passed argument are exactly equal, otherwise returns false.