Question

Please fill in the remaining code necessary and follow the instructions below this is an abstract...

Please fill in the remaining code necessary and follow the instructions below this is an abstract class; it represents an department in the company. This class cannot be instantiated (objects created), but it serves as the parent for other classes.

Department – This class represents a department within the company.

1. Provide the implementation (the body) for the following methods:

public int getDepartmentID())

public String getDepartmentName())

public Manager getManager())

2. Fix the implementation for the following method– substitute “blah” with the actual value:

public String toString()

3. Provide the implementation (the body) for the following methods:

public String getManagerName()

public void setDepartmentName(String name)

public void setDepartmentManager(Manager deptManager)

public void addEmployee(Employee employee)

package payrollsystem_phase1;

import java.util.ArrayList;

/**
* The Department class represents a department within a company. Departments have a
* list of employees and a manager.
*
*/
public class Department
{
// static variable
private static int nextDeptID = 1;
  
// instance variables
private int departmentID;
private String departmentName;
private Manager departmentManager;
private ArrayList listOfEmployees = new ArrayList<>();
  
  
/**
* This is the default constructor. It initializes the fields to default values.   
*/
public Department()
{
departmentID = nextDeptID;
departmentName = "";
departmentManager = new Manager();
  
nextDeptID++;
}
  
  
/**
* This constructor sets the department's id, name, and manager.   
* @param name Department's name.
* @param manager Department's manager.
*/
public Department(String name, Manager manager)
{
departmentID = nextDeptID;
departmentName = name;
departmentManager = manager;
  
nextDeptID++;
}
  
  
/**
* The getDepartmentID method returns the department's id number.
* @return The department's id.
*/
public int getDepartmentID()
{
// provide implementation
}
  
  
/**
* The getDepartmentName method returns the department's name.
* @return The department's name.
*/
public String getDepartmentName()
{
// provide implementation
}
  
  
/**
* The getManager method returns a reference to the department manager.
* @return The department manager.
*/
public Manager getManager()
{
// provide implementation
}
  
  
/**
* The getManagerName method returns the department manager's first and last name.
* @return The department manager's first and last name separated by a space.
*/
public String getManagerName()
{
// provide implementation
}
  
  
/**
* The setDepartmentName method sets the name for this department.
* @param name The value to store in the name field for this department.
*/
public void setDepartmentName(String name)
{
// provide implementation
}
  
  
/**
* The setDepartmentManager method sets the manager for this department.
* @param deptManager The value to store in the manager field for this department.
*/
public void setDepartmentManager(Manager deptManager)
{
// provide implementation
}
  
  
/**
* The addEmployee method adds an employee to the list of employees for this department.
* @param employee The employee to be added.
*/
public void addEmployee(Employee employee)
{
// provide implementation
}
  
  
/**
* The toString method returns a string containing the department's data.
* @return A String containing the Department's information: id, name,
* manager, and list of employees.
*/
@Override
public String toString()
{
String managerInfo;
  
if( departmentManager != null )
managerInfo = "blah";
else
managerInfo = "None";
  
  
String output = String.format( "\n%-30s %s \n%-30s %s \n%-30s %s \n%-30s %-10s %-15s %s",
"Department ID:", "blah",
"Department Name:", "blah",
"Department Manager:", managerInfo,
"List of Employees:", "ID", "FIRST NAME", "LAST NAME");
  
if( listOfEmployees == null || listOfEmployees.isEmpty() )
{
output += "None";
}
else
{
for( Employee emp : listOfEmployees )
{
output += String.format( "\n%-30s %-10s %-15s %s",
"",
emp.getEmployeeID(),
"blah",
"blah");
}
}

return output;
}
  
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.ArrayList;

class Manager {
   private String firstName;
   private String LastName;

   public String getFirstName() {
       return firstName;
   }

   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }

   public String getLastName() {
       return LastName;
   }

   public void setLastName(String lastName) {
       LastName = lastName;
   }
}

class Employee {
   private int employeeID;
   private String FirstName;
   private String LastName;

   public int getEmployeeID() {
       return employeeID;
   }

   public void setEmployeeID(int employeeID) {
       this.employeeID = employeeID;
   }

   public String getFirstName() {
       return FirstName;
   }

   public void setFirstName(String firstName) {
       FirstName = firstName;
   }

   public String getLastName() {
       return LastName;
   }

   public void setLastName(String lastName) {
       LastName = lastName;
   }
}

/**
* The Department class represents a department within a company. Departments
* have a list of employees and a manager.
*
*/

public class Department {
// static variable
   private static int nextDeptID = 1;

   // instance variables
   private int departmentID;
   private String departmentName;
   private Manager departmentManager;
   private ArrayList<Employee> listOfEmployees = new ArrayList<>();

   /**
   * This is the default constructor. It initializes the fields to default values.
   */

   public Department() {
       departmentID = nextDeptID;
       setDepartmentName("");
       setDepartmentManager(new Manager());

       nextDeptID++;
   }

   /**
   * This constructor sets the department's id, name, and manager.
   *
   * @param name    Department's name.
   * @param manager Department's manager.
   */

   public Department(String name, Manager manager) {
       departmentID = nextDeptID;
       setDepartmentName(name);
       setDepartmentManager(manager);

       nextDeptID++;
   }

   /**
   * The getDepartmentID method returns the department's id number.
   *
   * @return The department's id.
   */

   public int getDepartmentID() {
       return departmentID;
   }

   /**
   * The getDepartmentName method returns the department's name.
   *
   * @return The department's name.
   */

   public String getDepartmentName() {
       return departmentName;
   }

   /**
   * The getManager method returns a reference to the department manager.
   *
   * @return The department manager.
   */

   public Manager getManager() {
       return departmentManager;
   }

   /**
   * The getManagerName method returns the department manager's first and last
   * name.
   *
   * @return The department manager's first and last name separated by a space.
   */

   public String getManagerName() {
       return departmentManager.getFirstName() + " " + departmentManager.getLastName();
   }

   /**
   * The setDepartmentName method sets the name for this department.
   *
   * @param name The value to store in the name field for this department.
   */

   public void setDepartmentName(String departmentName) {
       this.departmentName = departmentName;
   }

   /**
   * The setDepartmentManager method sets the manager for this department.
   *
   * @param deptManager The value to store in the manager field for this
   *                    department.
   */

   public void setDepartmentManager(Manager departmentManager) {
       this.departmentManager = departmentManager;
   }

   /**
   * The addEmployee method adds an employee to the list of employees for this
   * department.
   *
   * @param employee The employee to be added.
   */

   public void addEmployee(Employee employee) {
       listOfEmployees.add(employee);
   }

   /**
   * The toString method returns a string containing the department's data.
   *
   * @return A String containing the Department's information: id, name, manager,
   *         and list of employees.
   */

   @Override
   public String toString() {
       String managerInfo;

       if (departmentManager != null)
           managerInfo = getManagerName();
       else
           managerInfo = "None";

       String output = String.format("\n%-30s %s \n%-30s %s \n%-30s %s \n%-30s %-10s %-15s %s", "Department ID:",
               getDepartmentID(), "Department Name:", getDepartmentName(), "Department Manager:", managerInfo,
               "List of Employees:", "ID", "FIRST NAME", "LAST NAME");

       if (listOfEmployees == null || listOfEmployees.isEmpty()) {
           output += "None";
       } else {
           for (Employee emp : listOfEmployees) {
               output += String.format("\n%-30s %-10s %-15s %s", "", emp.getEmployeeID(), emp.getFirstName(),
                       emp.getLastName());
           }
       }

       return output;
   }

}

Add a comment
Know the answer?
Add Answer to:
Please fill in the remaining code necessary and follow the instructions below this is an abstract...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so...

    Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so they throw exceptions when the following errors occur. - The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999. - The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift. - The ProductionWorker class should thrown anexception named InvalidPayRate when it receives a negative number...

  • In the processLineOfData method, write the code to handle case "H" of the switch statement such...

    In the processLineOfData method, write the code to handle case "H" of the switch statement such that: • An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows: Double.parseDouble(rate) Call the parsePaychecks method in this class passing the Hourly Employee object created in the previous step and the checks variable. Call the...

  • //*Manager.java*// public interface Manager { public void handleCrisis(); } _________________________________________________________ /**Employee.java**/ Public abstract class Employee {...

    //*Manager.java*// public interface Manager { public void handleCrisis(); } _________________________________________________________ /**Employee.java**/ Public abstract class Employee { protected final String name; protected final int id; public Employee(String empName, int empId) { name = empName; id = empId; } public Employee() { name = generatedNames[lastGeneratedId]; id = lastGeneratedId++; } public String getName() { return name; } public int getId() { return id; } //returns true if work was successful. otherwise returns false (crisis) public abstract boolean work(); public String toString() { return...

  • Rewrite following code down below using Factory Pattern. -------------------------Staff.java--------------------------- import java.util.*; public class Staff extends Employee...

    Rewrite following code down below using Factory Pattern. -------------------------Staff.java--------------------------- import java.util.*; public class Staff extends Employee {    private int HourlyRate;    /**Constructor Staff which initiates the values*/    public Staff() {    super();    HourlyRate=0;    }    /**Overloaded constructor method    * @param ln last name    * @param fn first name    * @param ID Employee ID    * @param sex Sex    * @param hireDate Hired Date    * @param hourlyRate Hourly rate for the work...

  • In the processLineOfData, write the code to handle case "H" of the switch statement such that:...

    In the processLineOfData, write the code to handle case "H" of the switch statement such that: An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows:               Double.parseDouble(rate) Call the parsePaychecks method in this class passing the HourlyEmployee object created in the previous step and the checks variable. Call the findDepartment method...

  • DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to...

    DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to be DataSetEmployee. DataSetEmployee should extend ArrayList<Employee> and have no instance variables. You'll have to decide what replaces the getPages concept for getMax/getMin. As a hint, what method of Employee returns a numeric value? Make a package com.acme.midmanager. This package should contain the Manager class. Make a package com.acme.personnel. This package should contain the DataSetEmployee class. Make a package com.acme.topmanagement. This package should contain the...

  • Previous class code: 1) Employee.java ------------------------------------------------------------------------------- /** * */ package main.webapp; /** * @author sargade *...

    Previous class code: 1) Employee.java ------------------------------------------------------------------------------- /** * */ package main.webapp; /** * @author sargade * */ public class Employee { private int empId; private String empName; private Vehicle vehicle; public Double calculatePay() { return null; } /** * @return the empId */ public int getEmpId() { return empId; } /** * @param empId * the empId to set */ public void setEmpId(int empId) { this.empId = empId; } /** * @return the empName */ public String getEmpName() { return...

  • Given attached you will find a file from Programming Challenge 5 of chapter 6 with required...

    Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: An empty string is given for the employee’s name. An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a...

  • Task 3: Main Program Create a main program class that: Creates three or more Nurse instances...

    Task 3: Main Program Create a main program class that: Creates three or more Nurse instances assigned to different shifts. Creates three or more Doctor instances. Creates three or more Patient instances with pre-determined names and manually assigned physicians chosen from the pool of Doctor instances previously created. Generates another 20 Patient instances using randomly generated names and randomly assigns them physicians chosen from the pool of Doctor instances previously created. Prints the toString() values for all employees. Prints the...

  • Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java...

    Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>();   // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString());       //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234");    // printing information System.out.println(part2.toString());    //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT