Skip to content

8 Exceptions and validation

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

  2. Modify the MonthlySalary property setter in the Employee class so that an ArgumentException is thrown if the monthly salary is less than or equal to 0. The message is: "The monthly salary cannot be negative".

  3. Adjust the constructors so they call the MonthlySalary property setter.

  4. Remove or comment out all code in your Main method.

  5. Add code that asks the user for data of a new employee as in the example below. Use the existing constructors and ToString() method. Your output should look like:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    Enter the name: Antoinette
    Enter the city: Leeuwarden
    Enter the department name: IT
    Enter the department location: Groningen
    Enter the monthly salary: -2300
    The monthly salary cannot be negative
    Your input has been processed.
    Enter the monthly salary: 2300
    Antoinette lives in Leeuwarden and works at department IT at Groningen and is an employee without right to a bonus
    Your input has been processed.