Answered step by step
Verified Expert Solution
Link Copied!

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:
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 3 Lnai 8726

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448440, 978-3662448441

More Books

Students also viewed these Databases questions