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

21. (10 points) Given the superclass Employee, create a subclass HourlyEmployee

ID: 3692335 • Letter: 2

Question

21. (10 points) Given the superclass Employee, create a subclass HourlyEmployee with a constructor that calls the parent constructor and sets the attribute hours which is of double datatype. public class Employee private int eid private Sting EName public Employee(int ID, String EName) (eid ID this. EName - EName:) public class HourlyEmployee 22. (10 points) Write an interface named CompanyFacts that has constants for name Address and merchantiD. Include methods to setManager, setHours, and setVacation

Explanation / Answer

21)

Employee.java

package org.students;

public class Employee
{
private int eid;
private String EName;
private double hours;
//parameterised constructor which is used to set the value
//for the instance variables eid,EName
public Employee(int eid, String eName) {
   this.eid = eid;
   EName = eName;
}

//parameterized constructor which is used to set the value
//for the instance variable hours
public Employee(double hours) {
   System.out.println("** Super Class Employee constructor ");
   this.hours = hours;
  
}

@Override
public String toString() {
   return "Employee [hours=" + hours + "]";
}

}

_______________________________________________________________________________________

HourlyEmployee.java

package org.students;

public class HourlyEmployee extends Employee {

   public HourlyEmployee(int eid, String eName) {
       super(eid, eName);

   }

   public HourlyEmployee(double hours) {
       //calling super class constructor from sub class.
       super(hours);
       System.out.println("** SubClass Hourly Employee constructor ");
      
      
   }

}

_________________________________________________________________________________________

output:

** Super Class Employee constructor
** SubClass Hourly Employee constructor
Employee [hours=25.0]

________________________________________________________________________________________

22)

CompanyFacts.java

package org.students;

public interface CompanyFacts
{
  
   //constants(every instance variable in the interface is public static and final)
   //so no need to declare each variable as public static final.
   String name= "Williams";
   String address = "church road,USA";
   public static final int merchantID = 2304;
  
   //every method in an interface is public and abstract.
   //we have to provide the implementation code for these methods
   //in its implementation classes
   public void setManager();
   public void setHours();
   public void setVacation();
  

}

___________________________________________________________________________________________

23)

Student.java

package org.students;

public class Student
{
private int SID;
private String SName;
protected static int count;

//Parameterized Constructor
public Student(int id, String N) {
   SID = id;
   SName = N;
}

//Getters and Setters
public int getSID() {
   return SID;
}
public void setSID(int id) {
   SID = id;
}
public String getSName() {
   return SName;
}
public void setSName(String N) {
   SName = N;
}

//Accessor method for static varible count
public static int getCount() {
   return count;
}

//Mutator method for static varible count
public static void setCount(int count) {
   Student.count = count;
}


}

_______________________________________________________________________________________

24)

static methods,private methods,parent class final methods cannot be overridden in java.

_________________________________________________________________________________________

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