111 lines
No EOL
4.5 KiB
Text
111 lines
No EOL
4.5 KiB
Text
[](https://classroom.github.com/a/3WioXqLZ)
|
|
:sectnums:
|
|
:nofooter:
|
|
:toc: left
|
|
:icons: font
|
|
:data-uri:
|
|
:source-highlighter: highlightjs
|
|
:stem: latexmath
|
|
|
|
= Inh.01 -- Employees
|
|
|
|
You are going to represent the various employees of a company:
|
|
|
|
* Workers
|
|
* Office employees
|
|
** Some are managers
|
|
|
|
IMPORTANT: This is a rather short assignment -- you are expected to read & understand the code carefully and reflect on how good your understanding of inheritance already is
|
|
|
|
== Class Descriptions
|
|
|
|
=== `Employee`
|
|
|
|
All employees have _common_ properties:
|
|
|
|
* Name
|
|
** Requirements:
|
|
*** At least two characters
|
|
*** First character is a letter (not a digit) _and_ is uppercase
|
|
** If invalid set to 'ERROR'
|
|
* Gender
|
|
* Department
|
|
* Salary
|
|
* Can represent themselves as a `string`
|
|
|
|
But nobody is _just_ an employee => everyone is either a `Worker`, `OfficeEmployee` or `Manager`, so there are _no_ instances of `Employee`.
|
|
|
|
==== String Representation
|
|
|
|
* Contains the name and the department the employee works at
|
|
* If gender is either male or female this information is added, but omitted for those employees who identify as divers
|
|
* Examples:
|
|
** `My name is Mia, I identify as female and I work at the department Accounting`
|
|
** `My name is Steph and I work at the department Marketing`
|
|
|
|
=== `Worker`
|
|
|
|
A worker is an employee which performs physical labor.
|
|
|
|
* They work a certain amount of hours each month
|
|
** This value cannot exceed 16 hours for 31 days a month and can also not be negative
|
|
*** Try to use https://learn.microsoft.com/en-us/dotnet/api/system.math.clamp?view=net-7.0[Math.Clamp] here
|
|
** You may ignore that months are usually shorter and that people have free weekends
|
|
* They get paid a certain amount per hour
|
|
** Which cannot be negative either
|
|
* Their salary is calculated by multiplying the hours worked by the wage per hour
|
|
* The string representation is extended by adding 'as a worker'
|
|
** Example: `My name is Max, I identify as male and I work at the department Welding as a worker`
|
|
** Do _not_ duplicate the basic part!
|
|
|
|
TIP: One constructor calls the `base` constructor, but the other one calls another _class_ constructor -- make sure you understand the difference and how the `base` constructor will eventually be called in both cases
|
|
|
|
=== `OfficeEmployee`
|
|
|
|
Some employees work at an office.
|
|
|
|
* An office clerk has a fixed salary per month
|
|
** Which cannot be negative
|
|
* The string representation is extended by adding 'as an employee'
|
|
|
|
==== `Manager`
|
|
|
|
A manager is the head of a department.
|
|
|
|
* Managers also work at an office
|
|
* They have a fixed salary per month, just like regular office employees, but that is increased by 20% to determine their actual salary
|
|
** Try to implement this using `base.Salary`
|
|
* The string representation is _changed_:
|
|
** Does not include gender information
|
|
** Example: `My name is Anna and I'm head of the Sales department`
|
|
|
|
== Tasks
|
|
|
|
* Try to create the class diagram _before_ looking at the provided starter code
|
|
** You need to learn how to turn a pure, textual description of a scenario into a class diagram and then into code => making it easier for yourself by cheating now will make it harder later on
|
|
* It is perfectly fine to _revise_ your diagram once you looked at the code and realized you had chosen an incorrect visibility modifier or data type,...
|
|
** You'll learn quite a lot about how to make these decisions by actively comparing my choices with the ones you made and trying to figure out how we reached different (or similar) conclusions
|
|
|
|
=== Class Diagram
|
|
|
|
* Your first task is to create a UML _class diagram_ for this application.
|
|
* Use https://plantuml.com/class-diagram[PlantUML] for this job
|
|
* Make sure to use the correct _visibility_ modifiers
|
|
* Include all _relationships_
|
|
** e.g. 'is a',...
|
|
|
|
=== Implementation
|
|
|
|
* Business as usual:
|
|
** Implement the application
|
|
** Unit Tests have been provided
|
|
* Take a detailed look at the provided XMLDoc: what could `<inheritdoc cref="..." />` mean and why do we suddenly need this tag now?
|
|
** Internet search is allowed 😉
|
|
|
|
NOTE: Make sure to carefully check which classes are `abstract` or `sealed` and how the inheritance structure is represented in code -- you'll have to do that by yourself soon
|
|
|
|
==== Sample Run
|
|
|
|
Take a look at `Program.cs`: _why_ do we get different outputs despite operating on a `List<Employee>` which only contains objects of type `Employee`?
|
|
|
|
image::pics/sample_run.png[Sample Run] |