In Java Class Employee will represent the superclass. This class is an example o
ID: 3698173 • Letter: I
Question
In Java
Class Employee will represent the superclass. This class is an example of re-use in your object-oriented design. It is already written and the Java code for Employee.java is provided for you below to copy and paste into your program. You do not need to create or modify this class code. Create a Class StudentEmployee, that will be derived from the Employee class. It should have fields to hold the following information: hoursWorked - The number of hours worked in the current two-week pay period isWorkStudy - True is the student is eligible for work study status; false otherwise payRate - The student's hourly pay rate constructor method accepts all six parameters as Strings and converts them to their appropriate primitive types Mutator and accessor methods for payRate. In the interests of time, we will skip mutator and accessor method for hoursWorked and isWorkStudy. Given more time you should add setter and getter methods for all fields (when it makes sense). toString - returns employeeName, employeeld, isWorking, hoursWorked, isWorkStudy, and payRate. each separated by tabs (for testing purposes) Design and implement a main method in class Hw6_q3_code.java that will prompt the user for a comma separated list of values representing the name, id, working status, hours worked, work study eligibility, and pay rate. Based on this user input, instantiate a new StudentEmployee object, using String.split to access the six parameter arguments, and then display the StudentEmployee object, using its toString() method, to test that the student employee's values were instantiated correctly. (See example below) Enter the student data: Stan Stanley, 123456789, true, 19, false, 10.95 Stan Stanley 1234S6789 true 19 false 10.95 For example, by using the comma character as the delimiter, we can pick apart the parameters needed to be passed to the constructor method of StudentEmployee by accessing the elements of params: string str = "stan stanley, l23456789, true, 19, false, 10.05" String [] parans = str.split(", ");Explanation / Answer
Employee.java
package org.students;
public class Employee {
//Instance variables
private String employeeName;
private int employeeId;
private boolean isWorking;
//Parameterized constructor
public Employee(String employeeName,String employeeId,String isWorking) {
super();
this.employeeName = employeeName;
this.employeeId = Integer.parseInt(employeeId);
this.isWorking = Boolean.parseBoolean(isWorking);
}
//Setters and getters
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public boolean isWorking() {
return isWorking;
}
public void setWorking(boolean isWorking) {
this.isWorking = isWorking;
}
//To Display the contents of the object
@Override
public String toString() {
return "Empoyee [employeeName=" + employeeName + ", employeeId="
+ employeeId + ", isWorking=" + isWorking + "]";
}
}
_______________________________________________________________________________
StudentEmployee.java
package org.students;
public class StudentEmployee extends Employee{
//Instance variables
private int hoursWorked;
private boolean isWorkStudy;
private double payRate;
//Parameterized constructor
public StudentEmployee(String employeeName,String employeeId,
String isWorking,String hoursWorked,String isWorkStudy,String payRate) {
super(employeeName, employeeId, isWorking);
this.hoursWorked=Integer.parseInt(hoursWorked);
this.isWorkStudy=Boolean.parseBoolean(isWorkStudy);
this.payRate=Double.parseDouble(payRate);
}
//Setters and getters
public double getPayRate() {
return payRate;
}
public void setPayRate(double payRate) {
this.payRate = payRate;
}
//To Display the contents of the object
@Override
public String toString() {
System.out.println(super.toString());
return "StudentEmployee [hoursWorked=" + hoursWorked + ", isWorkStudy="
+ isWorkStudy + ", payRate=" + payRate + "]";
}
}
_______________________________________________________________________________________
Hw6_q3_code.java
package org.students;
import java.util.Scanner;
public class Hw6_q3_code {
public static void main(String[] args) {
//Scanner object is used to get the inputs from the user.
Scanner sc=new Scanner(System.in);
System.out.print("Enter Student Data::");
//Read the string from the user
String data=sc.nextLine();
//Split method is used to split the string into tokens.
String params[]=data.split(",");
//Creating object of StudentEmployee class by passing the parameters.
StudentEmployee se=new StudentEmployee(params[0],params[1],params[2],params[3],params[4], params[5]);
//Diaplying the Contents of StudentEmployee Object
System.out.println(se.toString());
}
}
_____________________________________________________________________________________
output:
Enter Student Data::Stan Stanley,123456789,true,19,false,10.05
Empoyee [employeeName=Stan Stanley, employeeId=123456789, isWorking=true]
StudentEmployee [hoursWorked=19, isWorkStudy=false, payRate=10.05]
_____________________________________________________________________________________
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.