Skip to content

2 Encapsulation and constructor chaining

  1. Continue with the project from the previous chapter. It contains the Program and Person classes as you left them there.

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

    Person with BonusThreshold, private fields and properties, chained constructors, yearly income and bonus check Person with BonusThreshold, private fields and properties, chained constructors, yearly income and bonus check

    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.