· name: The name field is a String object that holds theemployee’s name · idNumb
ID: 3616212 • Letter: #
Question
· name: The name field is a String object that holds theemployee’s name
· idNumber:The idNumber is an int variable that holds the employee’s IDnumber
· department: The department field is a String object that holds thename of the department where the employee works
· position:The position field is a String object that hold theemployee’s job title
§ Write appropriate mutator methods that store values in these fieldsand accessor methods that return the values in these fields.
§ Write the default constructor, the parameter constructor thatreceives 4 parameters of name, idNumber, department, position andthe copy constructor that accepts an employeeRec object.
§ Write toString method to display the contents as the followingformat:
Employee: Susan – ID: 47899– Department: Accounting – Position: Vice President
2. Write a separate programEmployeeReport.java
§ creates three EmployeeRec objects :
-Object employee1 by using thedefault constructor and mutator methods to set values of fields
-Object employee2 by using theparameter constructor.
-Object employee3 by using the copyconstructor.
The information of these objects asfollows:
Name
ID number
Department
Position
1. Susam Meyers
47899
Accounting
Vice President
2. Mark Jones
39119
IT
Programmer
3. Joy Rogers
81774
Manufacturing
Engineer
§ display the data for each employee on the screen by using toStringmethod
Output should be:
Employee: Susam – ID: 47899 – Department: Accounting– Position: Vice President
Employee: Mark Jones – ID: 39119 – Department: IT– Position: Programmer
Employee: Joy Rogers – ID: 81774 – Department:Manufacturing – Position: Engineer
§ use the JOptionPane and the following example to display themessage Dialog box.
“Congratulations. You are successful to useobject!”
Hint: import javax.swing.JOptionPane;
JOptionPane.showMessageDialog(null, “the message”);
Name
ID number
Department
Position
1. Susam Meyers
47899
Accounting
Vice President
2. Mark Jones
39119
IT
Programmer
3. Joy Rogers
81774
Manufacturing
Engineer
Explanation / Answer
please rate - thanks previously given class with copyconstructor added and defaultconstructor changed class employee{
private String name;
private int idNumber;
private String department;
private String position;
//default constructor
public employee()
{
this.name="Susam Meyers";
idNumber=47899;
department="Accounting";
position="Vice President";
}
//parameterized constructor
public employee(String n,int id, String d, String p)
{
this.name=n;
this.idNumber=id;
this.department=d;
this.position=p;
}
//copy constructor
public employee(employee other)
{ name=other.name;
idNumber=other.idNumber;
department=other.department;
position=other.position;
}
public void setName(String n)
{
this.name=n;
}
public void setID(int d)
{
this.idNumber=d;
}
public void setDepartment(String d)
{
this.department=d;
}
public void setPosition(String p)
{
this.position=p;
}
public String getName()
{
return this.name;
}
public int getID()
{
return this.idNumber;
}
public String getDepartment()
{
return this.department;
}
public String getPosition()
{
return this.position;
}
public String toString()
{
System.out.println("Employee:"+getName()+"-ID:"+getID()+"-Department:"+getDepartment()+"-Position:"+getPosition());
return"Employee:"+name+"-ID:"+idNumber+"-Department:"+department+"-Position:"+position;
}
}
import java.util.*;
import javax.swing.*;
class EmployeeReport
{static Scanner in=new Scanner(System.in);
public static void main(String args[])
{String name,dept,position;
employee employee1=new employee();
employee employee2=new employee("MarkJones",39119,"It","Programmer");
employee employeetocopy=new employee("JoyRogers",81774,"Manufacturing","Engineer");
employee employee3=new employee(employeetocopy);
employee1.toString();
employee2.toString();
employee3.toString();
JOptionPane.showMessageDialog(null,"Congratulations. You aresuccessful to use object!");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.