Question: Modify the Employee class from the previous problem to add overloaded constructors: 1 . A no - arg constructor that assigns empty strings (

Modify the Employee class from the previous problem to add overloaded constructors:
1. A no-arg constructor that assigns empty strings ("") to the name, department, and position fields, and 0 to the idNumber field
2. A constructor that accepts an employees name and ID number and assigns them to appropriate fields. The department and position fields should be assigned an empty string ("")
3. A constructor that accepts the following values as arguments and assigns them to the appropriate fields: employees name, employees ID number, department, and position
Add a new method outputEmployeeInfo to display all employee information on-screen using System.out.println.
Use the new constructors to create employees and display their data.
The employee data to create:
No-arg constructor:
Name ID Number Department Position
Van Tyler 32532 Accounting Vice President
Diana Wells 35258 IT Programmer
Kathy Dixonian 87778 Manufacturing Engineer
Employee name and ID constructor:
Oliver Mills 12579 Accounting Vice President
Robert Goodman 86485 IT Programmer
Linda Cunningham 58255 Manufacturing Engineer
All-fields constructor:
Kendra Beck 75956 Accounting Vice President
Cathy McKinney 39858 IT Programmer
Irvin Warren 58525 Manufacturing Engineer
Use the outputEmployeeInfo() method for each employee object to display the information on screen.
Heres the code:
import java.util.Scanner;
class Employee {
private String name;
private int idNumber;
private String department;
private String position;
public Employee(){
this.name = "Susan Meyers";
this.idNumber =47899;
this.department = "Accounting";
this.position = "Vice President";
}
public Employee(String n, int id, String d, String p){
this.name = n;
this.idNumber = id;
this.department = d;
this.position = p;
}
public Employee(Employee other){
this.name = other.name;
this.idNumber = other.idNumber;
this.department = other.department;
this.position = other.position;
}
public void setName(String n){
this.name = n;
}
public void setIdNumber(int id){
this.idNumber = id;
}
public void setDepartment(String d){
this.department = d;
}
public void setPosition(String p){
this.position = p;
}
public String getName(){
return this.name;
}
public int getIdNumber(){
return this.idNumber;
}
public String getDepartment(){
return this.department;
}
public String getPosition(){
return this.position;
}
public String toString(){
System.out.println("Employee: "+ getName()+" ID: "+ getIdNumber()+" Department: "+ getDepartment()+
" Position: "+ getPosition());
return "Employee: "+ name +" ID: "+ idNumber +" Department: "+ department +" Position: "+ position;
}
}
public class EmployeeDemo {
static Scanner in = new Scanner(System.in);
public static void main(String args[]){
Employee employee1= new Employee();
Employee employee2= new Employee("Mark Jones", 39119,"IT", "Programmer");
Employee employeetocopy = new Employee("Joy Rogers", 81774, "Manufacturing", "Engineer");
Employee employee3= new Employee(employeetocopy);
employee1.toString();
employee2.toString();
employee3.toString();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!