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

I copied this straight from the Absolute Java 6th edition book but still getting

ID: 3790787 • Letter: I

Question

I copied this straight from the Absolute Java 6th edition book but still getting errors for some reason. I also appologize as I dont know how to paste code properly so if this looks wrong I do appologize. Here is my Class:

package programproject7;


import java.sql.Date;

public class Employee {
  
private String name;
private Date hireDate;
  
public Employee(){
  
name = "No name";
hireDate = new Date("january",);
  
}
  
public Employee(String theName, Date theDate){
  
if(theName == null || theDate == null){
System.out.println("Fatal Error creating employee.");
System.exit(0);
}
name = theName;
hireDate = new Date(theDate);
  
}
  
public Employee(Employee orignalObject){
  
name = orignalObject.name;
hireDate = new Date(originalObject.hireDate);
}
  
public String getName(){
  
return name;
}
  
public Date getHireDate(){
  
return new Date(hireDate);
}
  
public void setName(String newName){
  
if (newName ==null){
System.out.println("Fatal Error setting employee name.");
System.exit(0);
}
else
name = newName;
}
  
public void setHireDate(Date newDate){
if(newDate == null){
System.out.println("Fatal Error setting employee hire " + "date.");
System.exit(0);
}
else hireDate = new Date(newDate);
}
  
@Override
public String toString(){
  
return (name + " " + hireDate.toString());
}
  
public boolean equals (Employee otherEmployee){
  
return(name.equals(otherEmployee.name) &&
hireDate.equals(otherEmployee.hireDate));
}
}

Explanation / Answer

Hi,I have modified the code.It compiled successfull. Just add the main to work on it.
Actually, there was only one mistake all over the program i.e the program was creating a new Date object by passing the Date object itself. why we need to create new instance of date object when we have that object itself

This is the modified code :

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote