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

This seems like a super long question, but I need need to get a good start with

ID: 3653586 • Letter: T

Question

This seems like a super long question, but I need need to get a good start with it and some instructions as to where to go from there. If you could put notes on the code to show what everything is doing, that would be a huge help.

Class Employee has instance variables firstName, lastName, birthDate, hireDate and a variable to keep track of count of Employee objects. Members birthDate and hireDate are references to Date objects that have instance variables month, day and year. This demonstrates that a class can have references to objects of other classes. Note that class Employee does not import class Date because both classes are in the same default package (same project folder).

Date Class

Explanation / Answer

public class Date {

private int month;
private int day;
private int year;
private static final int[] daysPerMonth = {0,31,28,31,30
,31,30,31,31,30,31,30,31};
private static final String[] monthName = {"No name","January"
,"February","March","April","May","June","July","August",
"September","October","November","December"};

public Date(int month,int day,int year )
{
this.month = checkMonth(month);
this.year = checkYear(year);
this.day = checkDay(day);
}

public int checkMonth(int month)
{
if(month > 0 && month <=12)
return month;
else
throw new IllegalArgumentException("Month must be between 1-12");
}

public int checkYear(int year)
{
if(year>=0)
return year;
else
throw new IllegalArgumentException("Year must be greater than 0");
}

public int checkDay(int day)
{
if(day>0 && day <= daysPerMonth[month])
return day;
if(month==2 && day==29 && (year%400 == 0 || (year%4==0 && year%100!=0)))
return day;

throw new IllegalArgumentException("Day out of Range for " +
"Specified month and year");
}

public String toString()
{
return String.format("%s %d, %d",monthName[month],day,year );
}

public int getMonth()
{
return month;
}
}

public class Employee
{
private String firstName;
private String lastName;
private Date hireDate;
private Date birthDate;
private static int Number_Of_Employees =0;

public Employee(String first, String last, Date dateHire ,Date dateBirth)
{
firstName = first;
lastName = last;
hireDate = dateHire;
birthDate = dateBirth;
Number_Of_Employees++;
}

public static int getCount()
{
return Number_Of_Employees;
}

public Date getBithDate()
{
return birthDate;
}

public Date getHireDate()
{
return hireDate;
}
public void setBirthDate(Date date)
{
birthDate = date;
}
public void setHireDate(Date date)
{
hireDate = date;
}
public void setFirstName( String first )
{
firstName = first;
}

public String getFirstName()
{
return firstName;
}

public void setLastName( String last )
{
lastName = last;
}

public String getLastName()
{
return lastName;
}

@Override
public String toString()
{
return String.format( "%s %s birthday : %s Hire date : %s",
getFirstName(), getLastName(), birthDate, hireDate );
}
}

public class EmployeeTest
{
public static void main(String[] args)
{
Date birthDate= new Date(10,14,1986);
Date hireDate= new Date(5,1,2008);
Employee employee = new Employee("Bob","jones",hireDate,birthDate);
System.out.printf("%s ",employee);
birthDate= new Date(7,10,1993);
hireDate= new Date(1,1,2012);
employee = new Employee("Bob","jones",hireDate,birthDate);
System.out.printf("%s ",employee);
system.out.printf("Number of employees: %d ",Employee.getCount());
}
}

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