Skip to content

2 Encapsulation and constructor chaining

  1. If needed, retrieve the OOP Company project up to chapter 1 from DLO. It contains the Program and Person classes as you left them at the end of chapter 1.

  2. Change the Person class according to the class diagram below:

    Mermaid diagram Mermaid diagram

    a) Add the constant BonusThreshold.
    b) Make the four non-static attributes private.
    c) Add properties for these four attributes (properties are not shown in the class diagram).
    d) Apply constructor chaining to the three constructors.
    e) Add the HasRightToBonus() method. It returns true if the monthly salary is greater than or equal to BonusThreshold.

  3. Fix any errors that have arisen in your Main method (access the attributes via their properties).

  4. Remove the last two lines of code (both starting with Console.WriteLine) and add code so that your output looks like this:

    1
    2
    3
    4
    5
    6
    7
    8
    0
    1
    1
    2
    2
    4
    Mark earns 10000,00 and has right to a bonus.
    Caroline earns 4000,00 and has no right to a bonus.