Use the following UML diagram to create three class definitions. Recognize the s
ID: 3701879 • Letter: U
Question
Use the following UML diagram to create three class definitions.
Recognize the significance of the triangle in the UML and include the appropriate "extends" clause in the source files.
Use the following table to determine how to code the toString method for each class.
Class
Example output of System.out.print(object.toString() ;
Employee
Employee: John Doe, 1234567
Foreman
Jane Roe is a foreman in the Shipping area.
LineWorker
Frank Jones is a line worker on Shift 1.
Create a 4th file, an application class that includes a main function that performs the following operations.
Create 2 Employee objects who are neither Foreman nor LineWorker
1 of the Employee objects must be created using the constructor that contains parameters.
1 of the Employee objects must be created with the constructor that takes no arguments. For this instance, use the mutator methods to set the values.
Create 2 Foreman objects
1 of the Foreman objects must be created using the constructor that contains parameters.
1 of the Foreman objects must be created with the constructor that takes no arguments. For this instance, use the mutator methods to set the values.
Create 2 LineWorker objects
1 of the LineWorker objects must be created using the constructor that contains parameters.
1 of the LineWorker objects must be created with the constructor that takes no arguments. For this instance, use the mutator methods to set the values.
Print all 6 objects by printing calls to toString().
Note, it is not necessary to prompt the user to enter the values for the fields. You can hard code the values.
Class
Example output of System.out.print(object.toString() ;
Employee
Employee: John Doe, 1234567
Foreman
Jane Roe is a foreman in the Shipping area.
LineWorker
Frank Jones is a line worker on Shift 1.
Explanation / Answer
package emp;
public class Employee {
private int empId;
private String empname;
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getEmpname() {
return empname;
}
public void setEmpname(String empname) {
this.empname = empname;
}
public Employee(int empId, String empname) {
super();
this.empId = empId;
this.empname = empname;
}
public Employee() {
super();
}
@Override
public String toString() {
return "Employee [empId=" + empId + ", empname=" + empname + "]";
}
}
//2.
package emp;
public class Foreman {
private int fId;
private String fName;
public Foreman() {
super();
}
public Foreman(int fId, String fName) {
super();
this.fId = fId;
this.fName = fName;
}
public int getfId() {
return fId;
}
public void setfId(int fId) {
this.fId = fId;
}
public String getfName() {
return fName;
}
public void setfName(String fName) {
this.fName = fName;
}
@Override
public String toString() {
return "Foreman [fId=" + fId + ", fName=" + fName + "]";
}
}
//3.
package emp;
public class LineWorker {
private int lineId;
private String lineName;
public LineWorker() {
super();
}
public LineWorker(int lineId, String lineName) {
super();
this.lineId = lineId;
this.lineName = lineName;
}
public int getLineId() {
return lineId;
}
public void setLineId(int lineId) {
this.lineId = lineId;
}
public String getLineName() {
return lineName;
}
public void setLineName(String lineName) {
this.lineName = lineName;
}
@Override
public String toString() {
return "LineWorker [lineId=" + lineId + ", lineName=" + lineName + "]";
}
}
//4.test class
package emp;
public class MainTest {
public static void main(String[] args) {
Employee e1=new Employee(1002,"tarun");
Employee e2=new Employee();
e2.setEmpId(1005);
e2.setEmpname("teja");
Foreman f1=new Foreman(20003,"chiiti");
Foreman f2=new Foreman();
f2.setfId(20005);
f2.setfName("bujji");
LineWorker lw1=new LineWorker(70003,"Indra");
LineWorker lw2=new LineWorker();
lw2.setLineId(70005);
lw2.setLineName("laxmipathi");
System.out.println(e1);
System.out.println(e2);
System.out.println(f1);
System.out.println(f2);
System.out.println(lw1);
System.out.println(lw2);
}
}
/*OutPut:-
Employee [empId=1002, empname=tarun]
Employee [empId=1005, empname=teja]
Foreman [fId=20003, fName=chiiti]
Foreman [fId=20005, fName=bujji]
LineWorker [lineId=70003, lineName=Indra]
LineWorker [lineId=70005, lineName=laxmipathi]
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.