Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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:
A noarg constructor that assigns empty strings to the name, department, and position fields, and to the idNumber field
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
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 onscreen using System.out.println.
Use the new constructors to create employees and display their data.
The employee data to create:
Noarg constructor:
Name ID Number Department Position
Van Tyler Accounting Vice President
Diana Wells IT Programmer
Kathy Dixonian Manufacturing Engineer
Employee name and ID constructor:
Oliver Mills Accounting Vice President
Robert Goodman IT Programmer
Linda Cunningham Manufacturing Engineer
Allfields constructor:
Kendra Beck Accounting Vice President
Cathy McKinney IT Programmer
Irvin Warren 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 ;
this.department "Accounting";
this.position "Vice President";
public EmployeeString n int id String d String p
this.name n;
this.idNumber id;
this.department d;
this.position p;
public EmployeeEmployee other
this.name other.name;
this.idNumber other.idNumber;
this.department other.department;
this.position other.position;
public void setNameString n
this.name n;
public void setIdNumberint id
this.idNumber id;
public void setDepartmentString d
this.department d;
public void setPositionString 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.printlnEmployee: getName ID: getIdNumber Department: getDepartment
Position: getPosition;
return "Employee: name ID: idNumber Department: department Position: position;
public class EmployeeDemo
static Scanner in new ScannerSystemin;
public static void mainString args
Employee employee new Employee;
Employee employee new EmployeeMark Jones", IT "Programmer";
Employee employeetocopy new EmployeeJoy Rogers", "Manufacturing", "Engineer";
Employee employee new Employeeemployeetocopy;
employeetoString;
employeetoString;
employeetoString;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started