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

Hello. I need help connecting all 3 of my classes. I have notes where my program

ID: 3591526 • Letter: H

Question

Hello. I need help connecting all 3 of my classes. I have notes where my program is off currently. I am stumped right now.

Thank you :)

class EmployeeClassName {

  

      

       //get and return firstName, lastName, and employeeNumber

      

       private String firstName;

       private String lastName;

       private int employeeNumber;

      

       public String getFirstName()

       {

       return firstName;

       }

       public String getLastName()

       {

       return lastName;

       }

      

       public int getEmployeeNumber()

       {

       return employeeNumber;

       }

      

      

       public EmployeeClassName (String fn, String ln, int en)

       {

       firstName = fn;

       lastName = ln;

       employeeNumber = en;

       }

       }

       //address class

class Address{

       String street;

       String city;

       String state;

       String zipcode;

       // get and return street

       public String getStreet() {

       return street;

       }

       public String getCity() {

       return city;

       }

       public String getState() {

       return state;

       }

       public String getZipcode() {

       return zipcode;

       }

       // constructor of class

       public Address(String st, String c, String sta, String zip) {

           street = st;

           city = c;

           state = sta;

           zipcode = zip;  

               }

       }

      

       // date class

       class Date{ // better to use Class names starting with Capital letter

       int month;

       int day;

       int year;

       // get and return month

       public int getMonth() {

       return month;

       }

       public int getDay() {

       return day;

       }

       public int getYear() {

       return year;

       }

       }

      

//I'm trying to use Employee class to connect all three of my classes (EmployeeClassName, Address, and Date)

          

class EmployeeClass {

           super(fn, ln, st, c, sta, zip, month, day, year);

              

               // Class constructor

               EmployeeClass ( String fn, String ln, String st, String c, String sta, String zip, int month1, int day1, int year1, int employeeID ) {

//string that I would like read before I modify my subclasses

          

               }

  

          

           }      

      

      

      

      

      

      

      

//these are okay I think. I am just having trouble connecting all 3 of the classes above.

      

      

  

       class Employee extends EmployeeClass {

       public void main (String args []) {

       Employee( String fn, String ln, String st, String c, String sta, String zip, int month, int day, int year, String en, String as )

       {

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

      

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

       }

      

       }

      

      

      

       class SalariedEmployee extends EmployeeClass {

      

       double annualSalary;

      

       SalariedEmployee(String fn, String ln, String st, String c, String sta, String zip, int month, int day, int year, int en, double as)

       {

       super(fn, ln, st, c, sta, zip, month, day, year, en);

       annualSalary = as;

       }

       }

       //these are my two classes

       class HourlyEmployee extends EmployeeClass {

      

       double hourlyPayRate;

       double hoursWorked;

       double earnings;

      

       HourlyEmployee(String fn, String ln, int en,String street, String city, String state, String zipcode, int month, int day, int year, double hpr, double hw, double e)

       {

       super(fn, ln, street, city, state, zipcode, month, day, year, en);

       hourlyPayRate = hpr;

       hoursWorked = hw;

       earnings = e;

       }

       double getEarnings (){

       if (hoursWorked >40 ){

       earnings = hourlyPayRate * 1.5 * hoursWorked;

       }

       else{

       earnings = hourlyPayRate * hoursWorked;

       }

       return earnings;

       }

       }

       }

Explanation / Answer

/*

Hi! Looks like you are trying to connect the 3 classes: EmployeeClassName, Address, and Date in the Employee class.

*/

//This is the EmployeeClassName - Your First Class

class EmployeeClassName

{

//get and return firstName, lastName, and employeeNumber

private String firstName;

private String lastName;

private int employeeNumber;

public String getFirstName()

{

return firstName;

}

public String getLastName()

{

return lastName;

}

public int getEmployeeNumber()

{

return employeeNumber;

}

public EmployeeClassName(String firstName, String lastName, int employeeNumber)

{

this.firstName = firstName; //Always use full variable names to avoid confusions

this.lastName = lastName; //this refers to the EmployeeClassName object here.

this.employeeNumber = employeeNumber;

}

}

class Address

{

String street;

String city;

String state;

String zipcode;

// get and return street

public String getStreet()

{

return street;

}

public String getCity()

{

return city;

}

public String getState()

{

return state;

}

public String getZipcode()

{

return zipcode;

}

// constructor of class

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

{

this.street = street; //this refers to the Address object here.

this.city = city;

this.state = state;

this.zipcode = zipcode;

}

}

class Date

{

int month;

int day;

int year;

// get and return month

public int getMonth()

{

return month;

}

public int getDay()

{

return day;//Use proper indentation to avoid confusions

}

public int getYear()

{

return year;

}

// constructor of class

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

{

this.month = month; //this refers to the Address object here.

this.day = day;

this.year = year;

}

}

class EmployeeClass

{

/* super(fn, ln, st, c, sta, zip, month, day, year); - This is not needed because you are not inheriting any other class within EmployeeClass.*/

EmployeeClassName employeeClassName;

Address address;

Date date;

int employeeID;

EmployeeClass(String firstName, String lastName, String employeeNumber, String street, String city, String state, String zipcode, int month, int day, int year, int employeeID) //Here employeeID has been passed as an extra parameter

{ //Be consistent with the parameters of a constructor - you missed one parameter employeeNumber in SalariedEmployee(String fn, String ln, String st, String c, String sta, String zip, int month, int day, int year, int en, double as)

//Now a way of collecting all classes without inheriting them is to make their objects

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

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

this.date = new Date(month, day, year); //Note here: Be consistent with the order and type of parameters you are passing to the constructor.

this.employeeID = employeeID;

}

//We will have to create separate getters for all the parameters since we are not inheriting any other class.

public String getFirstName()

{

return employeeClassName.getFirstName();

}

//So, we use the objects to call the various methods of our Model Objects.

public String getLastName()

{

return employeeClassName.getLastName();

}

public int getEmployeeNumber()

{

return employeeClassName.getEmployeeNumber();

}

// get and return street

public String getStreet()

{

return address.getStreet();

}

public String getCity()

{

return address.getCity();

}

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;

}

}

/*Also, for the objects which are implementation specific like SalariedEmployee/Employee/HourlyEmployee, the order/type/number of parameters should be same as the constructor for EmployeeClass.*/