Assignment 1: Inheritance and Polymorphism Solved

25.00 $

Category: Tags: , , , , ,
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (1 vote)
In this program, you will create a database of Employees. Each Employee has a name & and ID.
Managers must also be part of this database. A manager is an employee as well. However, in addition to managers having all the characteristics of employees, managers also manage employees as subordinates. Therefore, a Manager has a list of Employees he/she manages as well as a count of how many subordinates he/she has.
Your application should ask the user for details to maintain the list of employees. For each employee, the program should ask the user for the name and whether or not the employee is a manager.
If the user specifies that the employee is a Manager, the program should ask the user how many subordinates he/she manages as well as their names. It should create a Manager object, and within the Manager object, create the subordinate Employees. The program should ask the user for the name of the subordinate employees and store their names with the Employee objects.
If the user specifies a Manager, the program should create an Employee object.
The new employee, either Manager or regular Employee, should be added to the database of Employees.
Finally, the program should print out a list of all employees. However, if an Employee is a Manager, it should also print out a list his/her subordinates Employees.
1
2
Sample Output
Project Name: A1
Classes: EmployeeSystem, Employee, Manager (Name all your classes and filenames appropriately).
• Implement an inheritance relationship between classes Employee and Manger based on the following inheritance structure:
• Use auto generation of code where you can!
Manager
Employee
2
3
Implement each of the following classes using the UML diagram for details on the class structure and following instructions for details on the logic to be implemented.
Put your name, class, etc. on Line 1 of ALL classes.
If you want to deviate and implement a slightly different solution, you can do that!
EMPLOYEE CLASS
Employee
# name: string
# id: string
+ <<property Name : string
+ <<property ID : string
+ <<constructor Employee()
+ <<constructor Employee(name: string)
Purpose: The Employee class abstracts the notion of an Employee.
Properties: Implement properties as seen in the UML Class Diagram.
Constructors: Implement constructors as seen in the UML Class Diagram.MANAGER CLASS
Manager
– subordinates: Employee[]
– numberOfSubordinates: int
+ <<constructor Manager()
+ <<constructor Manager(name: string)
+ PrintSubordinateList(): void
+ AddSubordinate(): Employee
Purpose: A Manager class abstracts the notion of a Manager. An apple is also an Employee.
Therefore, the Manager class should inherit from the Employee class.
Fields: Maintain fields for variables which you need to access from other methods! You definitely need an array of Employees and a count. Add any more that you need!
Constructors: Implement constructors for manager. For the overloaded constructor, be sure to redirect to the overloaded constructor of Student!
Methods
AddSubordinate() method
General Method Purpose: This method should add one employee to the subordinates array. So you
should ask the user details about one employee, create a new Employee and add it to the array. Remember
to increment the count of subordinates!
PrintSubordinateList() method
General Method Purpose: This method should loop through the subordinates array and print out a list of
all employees’ names.
4
5
EMPLOYEESYSTEM CLASS
EmployeeSystem
– listofEmployees : Employee[]
– countOfEmployees: int
– RunProgram() : void
– AddEmployee() : void
– PrintEmployeeList() : void
+ Main (args: string[]) : void
Purpose: This is the main program class, where the program starts. Implement a RunProgram
method (or similar), which starts up your program. Call this method from your Main method.
Fields: Maintain fields for variables which you need to access from other methods! You definitely need
an array of Employees and count. Add any more that you need!
Methods:
RunProgram() method
General Method Purpose: Maintain this method as your main method which runs the program. This means that this method should make sure you have an Employee array, start up the welcome street, prompt the user to enter employees as long as the user keeps saying yes, and finally displays a list of all
the employees.
AddEmployee() method
General Method Purpose: This method should add one employee to the array. Therefore, you should ask the user details about one employee as well as whether the employee is a manager or not. Depending on the answer, you should create either an Employee object or a Manager object.
If the user specifies that the employee is a manager, it should ask the user how many subordinates and you should call the relevant method from the Manager class, however many times as needed.
Make sure you add the employee (be it Manager or Employee) to the listOfEmployees and increment the
count! This uses upcasting!
DisplayEmployeeList() method
General Method Purpose: This method should loop through the listofEmployees and print out the name of all Employees.
If an Employee is a Manager, it should also print out a list of all its subordinates by calling the relevant method from the Manager class. Remember – you will need to use downcasting for this!

  • Archive-3.zip