Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this assignment you will create a new project and add to it 4 files: 3 of the

ID: 3702351 • Letter: I

Question

In this assignment you will create a new project and add to it 4 files: 3 of the files will be class definitions and the 4th file will be an application class that includes the main() function.

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

public class Employee {

   private String name;

   private int id;

   /**

   * @param name

   * @param id

   */

   public Employee(String name, int id) {

       super();

       this.name = name;

       this.id = id;

   }

   /**

   *

   */

   public Employee() {

       super();

      

   }

   /**

   * @return the name

   */

   public String getName() {

       return name;

   }

   /**

   * @param name the name to set

   */

   public void setName(String name) {

       this.name = name;

   }

   /**

   * @return the id

   */

   public int getId() {

       return id;

   }

   /**

   * @param id the id to set

   */

   public void setId(int id) {

       this.id = id;

   }

   /* (non-Javadoc)

   * @see java.lang.Object#toString()

   */

   @Override

   public String toString() {

       return "Employee: " + name + ", " + id ;

   }

  

}

public class LineWorker extends Employee {

  

   private int shiftNo;

   /**

   * @param name

   * @param id

   * @param shiftNo

   */

   public LineWorker(String name, int id, int shiftNo) {

       super(name, id);

       this.shiftNo = shiftNo;

   }

   public LineWorker(String name, int id) {

       super(name, id);

       // TODO Auto-generated constructor stub

   }

   public LineWorker() {

       // TODO Auto-generated constructor stub

   }

   /**

   * @return the shiftNo

   */

   public int getShiftNo() {

       return shiftNo;

   }

   /**

   * @param shiftNo the shiftNo to set

   */

   public void setShiftNo(int shiftNo) {

       this.shiftNo = shiftNo;

   }

   /* (non-Javadoc)

   * @see java.lang.Object#toString()

   */

   @Override

   public String toString() {

       return this.getName()+" is a line worker on Shift "+shiftNo+".";

   }

  

  

}

public class Foreman extends Employee {

   private String workingArea;

   /**

   * @return the workingArea

   */

   public String getWorkingArea() {

       return workingArea;

   }

   /**

   * @param workingArea the workingArea to set

   */

   public void setWorkingArea(String workingArea) {

       this.workingArea = workingArea;

   }

   /**

   * @param name

   * @param id

   * @param workingArea

   */

   public Foreman(String name, int id, String workingArea) {

       super(name, id);

       this.workingArea = workingArea;

   }

   public Foreman(String name, int id) {

       super(name, id);

       // TODO Auto-generated constructor stub

   }

   public Foreman() {

       // TODO Auto-generated constructor stub

   }

   /* (non-Javadoc)

   * @see java.lang.Object#toString()

   */

   @Override

   public String toString() {

       return this.getName() + " is a foreman in the "+ workingArea +" area.";

   }

  

}

public class TestEmployee {

   public static void main(String[] args) {

       Employee emp1 = new Employee();

       Employee emp2 = new Employee("Shubham Garg",123456);

       emp1.setId(1234567);

       emp1.setName("John Doe");

       Foreman foreman1 = new Foreman();

       Foreman foreman2 = new Foreman("Jane Roe",123456,"Shipping");

       foreman1.setName("Test1");

       foreman1.setId(121212);

       foreman1.setWorkingArea("Technology");

       LineWorker lw1 = new LineWorker();

       LineWorker lw2 = new LineWorker("TestLW",131313,2);

       lw1.setId(1414144);

       lw1.setName("Frank Jones");

       lw1.setShiftNo(1);

       System.out.println(emp1.toString());

       System.out.println(emp2.toString());

       System.out.println(foreman1.toString());

       System.out.println(foreman2.toString());

       System.out.println(lw1.toString());

       System.out.println(lw2.toString());

   }

}

Sample output:

Employee: John Doe, 1234567

Employee: Shubham Garg, 123456

Test1 is a foreman in the Technology area.

Jane Roe is a foreman in the Shipping area.

Frank Jones is a line worker on Shift 1.

TestLW is a line worker on Shift 2.