Could you look at this and fix the code and tell me what I missed,Thank you pack
ID: 3623267 • Letter: C
Question
Could you look at this and fix the code and tell me what I missed,Thank youpackage lab1;
import java.util.Date;
/**
* In this lab your challenge is to fix the code in both classes to use
* proper encapsulation and best practices
*
*
*/
public class Employee {
private String firstName;
private String lastName;
private String ssn;
private Date birthDate;
private boolean orientationCompleted;
private boolean metWithHr;
private boolean metDeptStaff;
private boolean revieweddeptPolicies;
private boolean movedIn;
private String cubeId;
public Employee() {
}
Date privategetBirthDate() {
return birthDate;
}
private void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
private String getCubeId() {
return cubeId;
}
private void setCubeId(String cubeId) {
this.cubeId = cubeId;
}
private String getFirstName() {
return firstName;
}
private void setFirstName(String firstName) {
// firstname needs validation
this.firstName = firstName;
}
private String getLastName() {
return lastName;
}
private void setLastName(String lastName) {
this.lastName = lastName;
}
private boolean isMetDeptStaff() {
return metDeptStaff;
}
private void setMetDeptStaff(boolean metDeptStaff) {
this.metDeptStaff = metDeptStaff;
}
private boolean isMetWithHr() {
return metWithHr;
}
private void setMetWithHr(boolean metWithHr) {
this.metWithHr = metWithHr;
}
private boolean isMovedIn() {
return movedIn;
}
public void setMovedIn(boolean movedIn) {
this.movedIn = movedIn;
}
private boolean isOrientationCompleted() {
return orientationCompleted;
}
private void setOrientationCompleted(boolean orientationCompleted) {
this.orientationCompleted = orientationCompleted;
}
private boolean isRevieweddeptPolicies() {
return revieweddeptPolicies;
}
private void setRevieweddeptPolicies(boolean revieweddeptPolicies) {
this.revieweddeptPolicies = revieweddeptPolicies;
}
private String getSsn() {
return ssn;
}
private void setSsn(String ssn) {
this.ssn = ssn;
}
private void completeOrientation() {
if(metWithHr && metDeptStaff
&& revieweddeptPolicies && movedIn) {
orientationCompleted = true;
}
}
private void meetWithHrForBenefitAndSalryInfo() {
this.metWithHr = true;
}
private void meetDepartmentStaff() {
this.metDeptStaff = true;
}
private void reviewDeptPolicies() {
this.revieweddeptPolicies = true;
}
private void moveIntoCubicle(String cubeId) {
this.cubeId = cubeId;
this.movedIn = true;
}
private String getStatus() {
if(this.orientationCompleted) {
return "Regular Employee";
} else {
return "New Hire";
}
}
}
package lab1;
/**
* In this lab your challenge is to fix the code in both classes to use
* proper encapsulation and best practices as explained by your instructor.
*
*
*/
public class Startup {
public static void main(String[] args) {
Employee employee = new Employee();
employee.setFirstName(null);
employee.firstName = "Peter";
employee.lastName = "Piper";
employee.ssn = "333-1234";
employee.meetWithHrForBenefitAndSalryInfo();
employee.meetDepartmentStaff();
employee.reviewDeptPolicies();
String status = employee.getStatus();
if(status.equals("New Hire")) {
System.out.println("Something went wrong with your code!"
+ " Should be 'Regular Employee'");
} else {
System.out.println(employee.firstName + " " + employee.lastName
+ " born on " + employee.birthDate.toString()
+ " SSN: " + employee.ssn + " is a " + employee.getStatus()
+ " located a Cube No. " + employee.cubeId);
}
}
}
Explanation / Answer
Dear,
Here is the code
The data members of a class are usually private to provide security to data and member functions of a can only access this data and they are usually public
Modified code and it is working fine and for the data values initialized the output will be
Something went wrong with your code! Should be 'Regular Employee'
Code
import
java.util.Date;
/**
* In this lab your challenge is to fix the code in both classes to use
* proper encapsulation and best practices
*
*
*/
{
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
&& revieweddeptPolicies && movedIn)
{
orientationCompleted =
}
}
{
}
{
}
{
}
{
}
{
{
}
{
}
}
}
package
lab1;
* In this lab your challenge is to fix the code in both classes to use
* proper encapsulation and best practices as explained by your instructor.
*
*
*/
public
class Startup
{
{
Employee employee =
employee.setFirstName(
employee.setFirstName( "Peter");
employee.setLastName("Piper");
employee.setSsn("333-1234");
employee.meetWithHrForBenefitAndSalryInfo();
employee.meetDepartmentStaff();
employee.reviewDeptPolicies();
String status = employee.getStatus();
{
System.out.println("Something went wrong with your code!"
+ " Should be 'Regular Employee'");
}
{
System.out.println(employee.getFirstName() + " "
+ employee.getLastName()+ " born on " + employee.getBirthDate()
+ " SSN: " + employee.getSsn() + " is a " + employee.getStatus()
+ " located a Cube No. " + employee.getCubeId());
}
}
}