8 Exceptions and validation
-
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.
-
Modify the
MonthlySalaryproperty setter in theEmployeeclass so that anArgumentExceptionis thrown if the monthly salary is less than or equal to 0. The message is: "The monthly salary cannot be negative". -
Adjust the constructors so they call the
MonthlySalaryproperty setter. -
Remove or comment out all code in your
Mainmethod. -
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.