Employee class: An Employee is a Person. An Employee also has an employee number
ID: 3791902 • Letter: E
Question
Employee class: An Employee is a Person. An Employee also has an employee number, and email address, and a date hired attribute. Write code for the constructor, mutator, accessor, and toString methods. import java.util.Date; dateHired = new Date(); public Employee() // default constructor // parameterized constructor (overloads default) public Employee(String name, String ssno, String id, String gender, String dob) // toString method public String toString() { return super.toString() + " Employee no:" + employeeNo + " Hired on: " + DateFormat.getDateInstance().format(dateHired); } Add an email method as follows: Create an email address with the person’s first initial, last name, and the last 4 digits of the ID followed by @acme.com. Example: John Doe, ’s email address would be JDoe6789@acme.com
need help with the email method!
Explanation / Answer
Employee.java
import java.text.DateFormat;
import java.util.Date;
public class Employee {
Date dateHired = new Date();
private String name;
private String employeeNo;
private String id;
private String gender;
private String dob;
public Employee() {
}
public Employee(String name, String ssno, String id, String gender,
String dob) {
this.name = name;
this.employeeNo = ssno;
this.id = id;
this.gender = gender;
this.dob = dob;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmployeeNo() {
return employeeNo;
}
public void setEmployeeNo(String employeeNo) {
this.employeeNo = employeeNo;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public String toString() {
return super.toString() + " Employee no:" + employeeNo + " Hired on: "
+ DateFormat.getDateInstance().format(dateHired);
}
public String email(){
return name.charAt(0)+name.substring(name.indexOf(" ")+1, name.length())+employeeNo+"@acme.com";
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.