The main part of today's lesson is an in-class group Object Oriented Design exercise. We will describe what we need a program to do, and your group will come up with a design to handle it. Your design will take the form of one or more class hierarchies, following the diagram style shown above.
One of the early inspirations for object oriented programming was the needs of programs for doing simulations. In fact, object oriented programming really began with a language called "Simula", which was designed for writing simulations. So, we're going to consider a problem that could be a part of a sophisticated program for doing financial simulations (in the world of personal finance ... I don't know anything about business-scale finance, being just a lowly professor). I want a program that will read in a file describing recurring events — like "every 14 days starting on 1/6/2016 I receive a paycheck" — and then simulate the day-by-day passing of time, printing out the events that occur in a day. [ Handout Form]
in0.txt | first 64 lines of output |
every 14 days start 1/6/2016 income Paycheck every 1 months start 1/15/2016 expense Mortgage Due every 1 months start 1/6/2016 expense Cable Due every 3 months start 3/21/2016 expense Water/Sewer Due every 3 months start 3/26/2016 income Stock Dividend every 1 months start 1/23/2016 expense Credit Card Due every 1 months start 1/11/2016 expense Car Payment Due every 1 months start 1/2/2016 expense Car Insurance Due every 1 months start 1/17/2016 expense Cell Phone Due every 1 days start 1/7/2016 prob 0.143 expense Groceries every 1 days start 1/1/2016 prob 0.15 expense Dinner Out every 7 days start 1/3/2016 prob 0.5 expense Breakfast Out every 4 days start 1/1/2016 prob 0.5 expense Gas every 1 days start 1/1/2016 prob 0.01 expense Car Repair every 12 months start 4/15/2016 expense Taxes Due every 1 months for 12 start 1/16/2016 expense Lazy Boy Layaway Payment Due |
1/1/2016: Dinner Out, Gas 1/2/2016: Car Insurance Due 1/3/2016: Breakfast Out 1/5/2016: Gas 1/6/2016: Paycheck, Cable Due 1/7/2016: Groceries, Dinner Out 1/9/2016: Gas 1/10/2016: Breakfast Out 1/11/2016: Car Payment Due 1/13/2016: Groceries 1/15/2016: Mortgage Due 1/16/2016: Lazy Boy Layaway Payment Due 1/17/2016: Cell Phone Due, Breakfast Out 1/18/2016: Dinner Out 1/20/2016: Paycheck 1/21/2016: Gas 1/23/2016: Credit Card Due 1/24/2016: Groceries 1/25/2016: Gas 1/29/2016: Gas 2/2/2016: Car Insurance Due, Dinner Out 2/3/2016: Paycheck 2/5/2016: Dinner Out 2/6/2016: Cable Due, Dinner Out, Gas 2/7/2016: Breakfast Out 2/8/2016: Groceries 2/10/2016: Dinner Out 2/11/2016: Car Payment Due, Groceries 2/12/2016: Groceries, Dinner Out 2/14/2016: Breakfast Out 2/15/2016: Mortgage Due ... |
Some of the lines in the input file probably deserve some explanation.
every 3 months start 3/26/2016 income Stock Dividend
every 14 days start 1/6/2016 income Paycheck
every 7 days start 1/3/2016 prob 0.5 expense Breakfast Out
every 1 months for 12 start 1/16/2016 expense Lazy Boy Layaway Payment Due
The system you're designing needs to be able to read all the events described in the sample input file, and any other file that follows the same basic format. The design itself should consist of one or more class hierarchies given in the same form as the diagram above.