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

Hello. Why is my date showing up as 00/00/0000? How can I correct this? class Em

ID: 3592367 • Letter: H

Question

Hello. Why is my date showing up as 00/00/0000? How can I correct this?

class EmployeeClassName {

  

      

      

      

       private String firstName;

       private String lastName;

      

      

       //get and return firstName, lastName, and employeeNumber

       public String getFirstName()

       {

       return firstName;

       }

       public String getLastName()

       {

       return lastName;

       }

      

      

      

       //refer to object EmployeeClassName

       public EmployeeClassName (String firstName, String lastName)

       {

       this.firstName = firstName;

       this.lastName = lastName;

      

      

       }

       }

      

class Address{

       private String street;

       private String city;

       private String state;

       private String zipcode;

       // get and return street, city, state, zipcode

       public String getStreet()

       {

       return street;

       }

       public String getCity()

       {

       return city;

       }

       public String getState()

       {

       return state;

       }

       public String getZipcode()

       {

       return zipcode;

       }

      

      

       // refer to Address object

       public Address(String street, String city, String state, String zipcode)

       {

           this.street = street;

           this.city = city;

           this.state = state;

           this.zipcode = zipcode;  

      

       }

       }

      

       class Date{

       private int month;

       private int day;

       private int year;

       public Date(int month, int day, int year) {

           // TODO Auto-generated constructor stub

       }

       // get and return month

       public int getMonth()

       {

           return month;

       }

       public int getDay()

       {

           return day;

       }

       public int getYear()

       {

       return year;

       }

       }

      

          

class EmployeeClass

{

   EmployeeClassName employeeClassName;

  

   Address address;

  

   Date date;

  

   int employeeID;

EmployeeClass(String firstName, String lastName, String street, String city, String state, String zipcode, int month, int day, int year, int employeeID) {

  

   this.employeeClassName = new EmployeeClassName( firstName, lastName);

  

   this.address = new Address(street, city, state, zipcode);

  

   this.date = new Date(month, day, year);

  

   this.employeeID = employeeID;

  

}

public String getFirstName ()

{

   return employeeClassName.getFirstName();

}

public String getLastName ()

{

   return employeeClassName.getLastName();

}

public String getStreet ()

{

   return address.getStreet();

}

public String getCity ()

{

   return address.getStreet();

}

public String getState()

{

   return address.getState();

}

public String getZipcode()

{

   return address.getZipcode();

}

public int getMonth()

{

   return date.getMonth();

}

public int getDay()

{

   return date.getDay();

}

public int getYear()

{

   return date.getYear();

}

public int getEmployeeID()

{

   return employeeID;

}

      

      

      

  

public static void main (String args [])

{

      

   //input name, address, date of hire, employeeID, annual salary

   SalariedEmployee employee1 = new SalariedEmployee("Suzie", "Palmer","135 Pheasant", "Argyle", "TX", "76226", 11, 17, 2010, 126000,40000);

   //output name, address, date of hire, employeeID, annual salary

   System.out.println(employee1.getFirstName() + " " + employee1.getLastName() + " " + employee1.getStreet() + " " + employee1.getCity() + " " + employee1.getState() + " " + employee1.getZipcode() + " " + employee1.date.getMonth() + "/" + employee1.date.getDay() + "/" + employee1.date.getYear() + " " + employee1.getEmployeeID() + " " + employee1.getAnnualSalary());

   // input name, address, date of Hire, employeeID, hours worked, hourly pay rate

   HourlyEmployee employee2 = new HourlyEmployee("Suzie", "Palmer", "135 Pheasant", "Argyle", "TX", "76226", 01, 17, 2010,41,4,30 );

   // return name, address, date of hire, employeeID, earnings

   System.out.println(employee2.getFirstName() + " " + employee2.getLastName() + " " + employee2.getStreet() + " " + employee2.getCity() + " " + employee2.getState() + " " + employee2.getZipcode() + " " + employee2.getMonth() + "/" + employee2.getDay() + "/" + employee2.getYear() + " " + employee2.getEmployeeID() + " " + employee2.getHoursWorked() + " " + employee2.getHourlyPayRate() + " " + employee2.getEarnings());

   // input name, address, date of Hire, employeeID, hours worked, hourly pay rate

   HourlyEmployee employee3 = new HourlyEmployee("Suzie", "Palmer","135 Pheasant", "Argyle", "TX", "76226", 01, 17, 2010, 41,4,50);

   // return name, address, date of hire, employeeID, earnings

   System.out.println(employee3.getFirstName() + " " + employee3.getLastName() + " " + employee3.getStreet() + " " + employee3.getCity() + " " + employee3.getState() + " " + employee3.getZipcode() + " " + employee3.getMonth() + "/" + employee3.getDay() + "/" + employee3.getYear() + " " + employee3.getEmployeeID() + " " + employee3.getHoursWorked() + " " + employee3.getHourlyPayRate() + " " + employee3.getEarnings());

}

}

class HourlyEmployee extends EmployeeClass

   {

          

           double hourlyPayRate;

           double hoursWorked;

           double earnings;

          

           HourlyEmployee(String firstName, String lastName, String street, String city, String state, String zipcode, int month, int day, int year, int employeeID, double hourlyPayRate, double hoursWorked) {

          

           super(firstName, lastName, street, city, state, zipcode, month, day, year, employeeID);

           this.hourlyPayRate = hourlyPayRate;

           this.hoursWorked = hoursWorked;

      

   }

          

           public double getHourlyPayRate()

           {

               return hourlyPayRate;

           }

          

           public double getHoursWorked()

           {

               return hoursWorked;

           }

           double getEarnings (){

           if (hoursWorked >40 ){

           earnings = hourlyPayRate * 1.5 * hoursWorked;

           }

           else{

           earnings = hourlyPayRate * hoursWorked;

           }

           return earnings;

           }

           }      

class SalariedEmployee extends EmployeeClass

{

          

          

       double annualSalary;

      

       SalariedEmployee(String firstName, String lastName, String street, String city, String state, String zipcode,

           int month, int day, int year, int employeeID, double annualSalary)

      

{

      

       super(firstName, lastName, street, city, state, zipcode, month, day, year, employeeID);

       // TODO Auto-generated constructor stub

      

       this.annualSalary = annualSalary;

}

       public double getAnnualSalary()

           {

               return annualSalary;

           }

          

}

  

  

      

a JavadocDeclarationConsole X kterminated> EmployeeClass [Java Application] /LibrarylJava/JavaVirtualMachines/jdk1.8.0 144.jdk/Contents/Home/bin/java (Oct 15, 2017, 1:04:24 AM) Suzie Palmer 135 Pheasant 135 Pheasant TX 76226 0/0/0 126000 Suzie Palmer 135 Pheasant 135 Pheasant TX 76226 Suzie Palmer 135 Pheasant 135 Pheasant TX 76226 40000.0 30.0 4.0 120.0 50.0 4.0 300.0 0/0/0 41

Explanation / Answer

It is showing 0 as it is taking the default value of int in your date class

Modified / corrected code

Your code is just fine but you haven't defined the constructor of Date class in your code , Here is the modified/correct implementation of Date class with constructor


class Date{

private int month;

private int day;

private int year;

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


// get and return month

public int getMonth()
{
return month;
}


public int getDay()
{
return day;
}


public int getYear()
{
return year;
}
}

PLEASE RATE !!

Thanks !