Homework Project 1


Part A

Do all of problem 3.13 (Employee Class) from the text, including the main, as written.   Inside the Employee class, use accessors and mutators whenever possible (so you should only be using the instance variables inside the accessors and mutators themselves).


Part B

Now, suppose a new company policy says that instead of the monthly salary we will now store the yearly salary.  We will need to make this change inside Employee and support the new usage, without breaking existing code (such as the old main) that relies on the old version.

Add an instance variable for yearly salary (with accessor and mutator). 

Remove the monthly salary instance variable from Employee.  If you wrote part A always going through accessors and mutators, this should break very little.

Change the existing public accessor and mutator for the monthly salary so that they will still work as originally expected, that is, the existing main method, unchanged, will have the same results it did when you ran it for part A, but inside Employee we are using the new instance variable. We should also be able to write new code using Employee that works with yearly salaries directly.

Think this through.  If someone does setYearlySalary(50000) what would they expect to happen if then then print getMonthlySalary()?  If someone does setMonthlySalary(1000) what would they expect to happen if they then print(getYearlySalary)?  Does your code do this? 

Add a new class with a main, NewEmployeeHarness, and test the additions to Employee.


Part C

Add a new class RetirementAccount, which has a balance and an interest rate defaulting to 1%

To the Employee class, add an instance variable of type RetirementAccount and an instance variable to store a percentage to save to the retirement account. By default employees do have a retirement account.

In Employee, add a method payday.  Assume that employees are paid twice a month.  Using the percentage to save, determine how much is being paid out directly and how much is being put in their retirement account, then add this paycheck's retirement amount to the account balance. Report to the user how much is being paid directly and how much was saved for retirement, and also report the current balance in the retirement account. (hint: your life later may be easier if you break this into several smaller methods) If there is no retirement account, print an error and report all the money for this paycheck is being paid out directly.

 


Part D

In a main (separate from previous mains) create a menu

0. Quit
1. Create Employee

If they create an employee

0. Return to main menu
1. Set salary (monthly format)
2. Set salary (yearly format)
3. Create payday report
4. Retirement Menu

If they choose retirement help

0. Return to previous menu
1. Set Retirement Percentage
2. View Retirement Scenarios

If they choose retirement scenarios, you will run three scenarios: 1% retirement contribution with a 1% interest rate on retirement savings, 10% retirement contribution with a 4% interest rate, and whatever their actual current retirement contribution and intrest rates are.  For each, show what their total take-home and total retirement contribution would be for a full year, assuming interest is paid monthly. Print the information and then offer them the option to upgrade to the higher interest rate, if they also change to a 10% retirement contribution.

(hint: if the user asks for retirement scenarios, should we put a year's worth of money into their real retirement account?)

For the menus, any time you are accepting a value (i.e. for age or salary), loop until you are given something valid (this should happen before it goes into a mutator, which is the last line of defense).


I will be grading based on using our course coding standards, including general standards like naming and standard class methods. A program that "runs and does what I asked" but not using these standards would get minimal credit. For instance, should mutators ever be talking to the user?