Question

In: Computer Science

Problem Description An organization has a number of buildings and employees. Every employee has an office...

Problem Description An organization has a number of buildings and employees. Every employee has an office in one of the buildings. The application will store the employees, the buildings, and the relationships between employees and buildings. Entity interface The Entity interface represents an employee or a building. Every object of type Entity has a single method, with the following characteristics. • Name: getName() • Returns the name of the entity (a String object) • No parameters Employee class This class implements the Entity interface. Every Employee object has a single attribute named name. Besides this field, the class has the following constructor and methods. • A constructor that takes as parameter, only the employee’s name and stores it appropriately. • A method named print() that prints the employee’s name. The method has no parameters and returns nothing. • The appropriate method to satisfy the interface Entity. Building class This class implements the Entity interface. Every Building object has an attribute named name. Besides this field, the class also uses a collection class (see below) to store the employees housed in the building. In addition, the class has the following constructor and methods. • A constructor that takes as parameter, only the building’s name and stores it appropriately. • A method named addEmployee() to add an employee to the collection that stores the list of employees housed in the building. The method returns nothing and has a single parameter of type Employee. • A method named print() that prints the building and the names of employees housed in the building The method has no parameters and returns nothing. • The appropriate method to satisfy the interface Entity. EntityList interface This interface represents a list of Entity objects and has two methods. • print(): The method has no parameters and returns nothing. The method prints every entity stored in the list. • addEntity(): The method has a single parameter of type Entity and returns nothing. It stores the Entity object supplied as parameter. The class should have a no-arg (default or otherwise) constructor. BuildingList class Implements the EntityList interface appropriately to store Building objects. You will need to cast objects as needed. Figure this out yourself. The class should have a no-arg (default or otherwise) constructor. EmployeeList class Implements the EntityList interface appropriately to store Employee objects. You will need to cast objects as needed. Figure this out yourself. Driver class Your driver class should do the following actions: • Create four Employee objects with your choice of employee names. • Create two Building objects with your choice of building names. • Store all Building and Employee objects in the proper list objects. • Store two of the employees in one of the buildings and the other two in the second building. • Invoke the print() method of EmployeeList to print the employees. • Invoke the print() method of BuildingList to print the buildings.

Solutions

Expert Solution

/**************************Entity.java**********************/


public interface Entity {

   public String getName();
}
/******************************Employee.java************************/


public class Employee implements Entity {

   //private data field
   private String name;

   /**
   *
   * @param name
   */
   public Employee(String name) {
       super();
       this.name = name;
   }

   @Override
   public String getName() {
       return name;
   }

   public void print() {

       System.out.println("Employee Name: " + name);
   }
}
/*************************Building.java*******************************/

import java.util.ArrayList;

public class Building implements Entity {

   //private data field
   private String buildingName;

   private ArrayList<Employee> employees;

   public Building(String buildingName) {
       super();
       this.buildingName = buildingName;
       employees = new ArrayList<>();
   }

   //constructor
   public void addEmployee(Employee employee) {

       employees.add(employee);
   }

   //getName method
   @Override
   public String getName() {
       return buildingName;
   }

   //print method
   public void print() {

       System.out.println("Building name: " + buildingName);
       System.out.println("The names of employees in the building: ");
       for (Employee employee : employees) {

           System.out.println(employee.getName());
       }
   }

}
/**************************************EntityList.java*********************************/


public interface EntityList {

   public void print();

   public void addEntity(Entity entity);
}
/****************************BuildingList.java*******************************./

import java.util.ArrayList;

public class BuildingList implements EntityList {

   //private data field
   private ArrayList<Building> buildings;

   public BuildingList() {

       buildings = new ArrayList<>();
   }

   //print method
   @Override
   public void print() {

       System.out.println("Building list is: ");
       for (Building building : buildings) {

           System.out.println(building.getName());
       }
   }

   //addEntity method
   @Override
   public void addEntity(Entity entity) {

       buildings.add((Building) entity);

   }

}
/*****************************Employee.java**********************************/

import java.util.ArrayList;

public class EmployeeList implements EntityList {
  
   //data field
   private ArrayList<Employee> employees;

   //no argument constructor
   public EmployeeList() {
       employees = new ArrayList<>();
   }

   //print method
   @Override
   public void print() {

       System.out.println("Employee list is: ");
       for (Employee employee : employees) {

           System.out.println(employee.getName());
       }
   }
  
   //add entity method
   @Override
   public void addEntity(Entity entity) {

       employees.add((Employee) entity);
   }

}
/******************************Driver.java*******************************/


public class Driver {

   public static void main(String[] args) {

       // create 4 employee object
       Employee employee1 = new Employee("Virat");
       Employee employee2 = new Employee("Dhoni");
       Employee employee3 = new Employee("Kohli");
       Employee employee4 = new Employee("Jadeja");
       // create two buildings
       Building building1 = new Building("ICC");
       Building building2 = new Building("BCCI");
       // add employees to buildings
       building1.addEmployee(employee1);
       building1.addEmployee(employee2);
       building2.addEmployee(employee3);
       building2.addEmployee(employee4);
       // create building list
       BuildingList buildingList = new BuildingList();
       buildingList.addEntity(building1);
       buildingList.addEntity(building2);
       // create employee list
       EmployeeList employeeList = new EmployeeList();
       employeeList.addEntity(employee1);
       employeeList.addEntity(employee2);
       employeeList.addEntity(employee3);
       employeeList.addEntity(employee4);
       // print information
       employeeList.print();
       buildingList.print();
   }
}
/*****************************output********************************/

Employee list is:
Virat
Dhoni
Kohli
Jadeja
Building list is:
ICC
BCCI

Please let me know if you have any doubt or modify the anser, Thanks :)


Related Solutions

About the organization: This fictional organization has a small, but growing, employee base, with 50 employees...
About the organization: This fictional organization has a small, but growing, employee base, with 50 employees in one small office. The company is an online retailer of the world's finest artisanal, hand-crafted widgets. They've hired you on as a security consultant to help bring their operations into better shape. Organization requirements: As the security consultant, the company needs you to add security measures to the following systems: An external website permitting users to browse and purchase widgets An internal intranet...
Your organization is transferring an employee to your Québec office. This employee is not familiar with...
Your organization is transferring an employee to your Québec office. This employee is not familiar with the Québec Parental Insurance Plan and has several questions about it. You have been asked to explain the differences between Employment Insurance and the Québec Parental Insurance Plan and what it means to the employee.
It is common for an organization to have different categories of employees, such that one Employee...
It is common for an organization to have different categories of employees, such that one Employee class can not easily describe all types of Employees.In this project, you will code a basic Employee class, and then a number of classes which derive from the Employee class (inherit), adding Employee specifics. An application program which stores info for one company will have use objects of different types to model the all employees. Part I:   The Employee Class First create the Employee...
Provide a detailed description of systems integration problem for a specific organization. Integration problem and organization...
Provide a detailed description of systems integration problem for a specific organization. Integration problem and organization can be real or fictitious. The integration problem should be complex enough to warrant utilization of advanced service integration technologies. The problem must involve more than three applications and five interactions among them.
Employee commitment is critical to product and service delivery excellence in every organization. As member of...
Employee commitment is critical to product and service delivery excellence in every organization. As member of the management team in a hospital, what quality management strategy could be employed by management to gain the commitment of the hospital staff in quality health service delivery.
Write a program in C to process weekly employee timecards for all employees of an organization...
Write a program in C to process weekly employee timecards for all employees of an organization (ask the user number of employees in the start of the program). Each employee will have three data items: an identification number, the hourly wage rate, and the number of hours worked during a given week.A tax amount of 3.625% of gross salary will be deducted. The program output should show the identification number and net pay. Display the total payroll and the average...
ABC Corporation has 350 employees. The distribution of number of sick days per employee per year...
ABC Corporation has 350 employees. The distribution of number of sick days per employee per year for the population of 350 employees is not highly skewed and has a mean of 12 and a standard deviation of 4. Suppose a simple random sample of 25 employees' number of sick days is taken, what is the probability that the sample of 25 will have mean number of sick days between 10 and 14? Show your work.
Write a program to process weekly employee time cards for all employees of an organization. Each...
Write a program to process weekly employee time cards for all employees of an organization. Each employee will have three data items: an identification number, the hourly wage rate, and the number of hours worked during a given week. Each employee is to be paid time and a half for all hours worked over 40. A tax amount of 3.625% of gross salary will be deducted. The program output should show the employee’s number and net pay. Display the total...
An important tactic for retaining employees is a good employee recognition program within the organization. Here...
An important tactic for retaining employees is a good employee recognition program within the organization. Here we what to examine how common they are in small (and large) businesses. With that in mind, you interview 376 of each kind. You find that 278 of the small organizations said they have an employee recognition program, while 316 of the large ones said they have an employee recognition program. We are trying to prove that larger organizations are more likely to have...
Grouper Company pays its office employee payroll weekly. Below is a partial list of employees and...
Grouper Company pays its office employee payroll weekly. Below is a partial list of employees and their payroll data for August. Because August is their vacation period, vacation pay is also listed. Employee --Earnings to July 31----    Weekly Pay-----    Vacation Pay to Be Received in August Mark Hamill $5,010    $200    --- Karen Robbins $4,310 $150    $300 Brent Kirk    $3,510 $110 $220 Alec Guinness    $8,210 $250 --- Ken Sprouse    $8,810 $330    $660...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT