Lab #7: Financial OOP

This lab continues from the in-class activity of the previous lecture. It's all about Object Oriented Design. Last class you started on a design for a program that solves the financial problem. Today you will finish that deisgn and implement it.

Gifts and Rules and Advice

  1. Gift: two input testing text files in0.txt and in2.txt
  2. Gift: A class for representing and dealing with dates — MyDate. Check out the documentation to learn how to use it, and download the compiled classfile (here), or via the command line with:

    curl -O http://faculty.cs.usna.edu/IC211/docs/lab07/MyDate.class

    MyDate has enough functionality to get the job done, but it may be that you want more. It's derived from the Java API class Calendar (actually from a subclass called GregorianCalendar) so you can look for extra methods there.

  3. Rules: Basic operating rules are:
    1. ALL FIELDS MUST BE PRIVATE! You may NOT use protected fields, or worse, public ones.
    2. The driver program's source code file should be named Lab7.java
    3. The input file will be given as the first command-line argument. Make sure to test with in0.txt and in2.txt.
    4. The number of days to simulate will be given as the second command-line argument.
    5. The simulation will start on 1 January 2017.
    6. If the program is run with fewer than two arguments, the following usage message will be shown:
      usage: java Lab7 <infilename> <numDays>
      and the program will terminate. If it is run with proper arguments, it will print its output as shown in the following sample run:

      in2.txt
      every 2 days start 1/7/2017 expense Ta
      every 1 days start 1/6/2017 income Dum
      sample run
      ~/$ java Lab7 in2.txt 10
      1/6/2017: Dum
      1/7/2017: Ta, Dum
      1/8/2017: Dum
      1/9/2017: Ta, Dum
      1/10/2017: Dum
      
    7. You will allow an optional third argument in order to force the random seed value if needed for testing (ie: the Submit system).

      // create a random object for use
      Random rand;
      if( args.length == 3 )
        rand = new Random(Long.parseLong(args[2]));
      else
        rand = new Random(System.currentTimeMillis());
      
      Note: You WILL have to pass this Random object as a parameter in your constructor for your objects that need random behavior.
    8. Advice: the "smarts" should be builtin to the classes themselves, not the driver program. That principle should guide your design. I suggest that your driver program be designed roughly like this:

      // set "today" to 1/1/2017
      for( int i=0; i < numDaysToSimulate; i++ ) {
        // ask each event whether they have something going on "today"
      
        // if any do, print them out
      
        // increment "today"
      }
      That way the driver is simple, and the "smarts" will be in each event class's code when it decides whether something's going on.

    Important: Lab7.java will read the input file. Reading dates (e.g. 2/5/2017) is greatly aided by the split method in String. See the documentation!


Part 1: Implement Your Class Hierarchy

Finalize version 1.0 of your design (remember the diagram from class?), write "the base class", and make sure that the base class source file actually compiles!

You should now be able to write the different parts of your class hierarchy design. If you decide some part of the design needs to change, that's OK, but make sure when you alter the base class that all its descendants agree on the change.

Part 2: Write main()

When you've completed your classes, write the driver main() method in Lab7.java!

Think you're finished? Don't just submit. Make your own test cases and be sure to test your program carefully and thoroughly. We are using different inputs than just the two test files we gave you here.

WARNING! You are limited to 5 submissions for this lab. You will be graded on your final submission, so make sure you have thoroughly tested it before uploading!

Here more expected output when using in0.txt:

~/$ java Lab7 in0.txt 34 9998
1/2/2017: Car Insurance Due, Dinner Out
1/5/2017: Gas
1/6/2017: Paycheck, Cable Due
1/8/2017: Dinner Out
1/9/2017: Gas
1/10/2017: Groceries, Dinner Out
1/11/2017: Car Payment Due
1/12/2017: Groceries, Dinner Out
1/13/2017: Dinner Out
1/14/2017: Dinner Out
1/15/2017: Mortgage Due
1/16/2017: Lazy Boy Layaway Payment Due
1/17/2017: Cell Phone Due
1/19/2017: Groceries
1/20/2017: Paycheck
1/21/2017: Dinner Out, Gas
1/22/2017: Dinner Out
1/23/2017: Credit Card Due
1/25/2017: Groceries
1/27/2017: Groceries
1/29/2017: Gas
1/30/2017: Dinner Out
1/31/2017: Groceries, Breakfast Out
2/2/2017: Car Insurance Due, Groceries
2/3/2017: Paycheck

Part 3: Javadoc

You are required to included nice Javadoc-style comments with your code. At a minimum you must use the @author, @param, and @return tags where they are appropriate. The Oracle Javadoc reference is a good overview for writing your comments if you need additional information. To generate your Javadoc documentation do the following:

javadoc -d doc -Xdoclint:all *.java
or, if you would like your javadoc to contain links back to Oracle's API:
javadoc -d doc -Xdoclint:all -link https://docs.oracle.com/en/java/javase/11/docs/api *.java

... which will create a directory "doc" in the current directory and put all the documentation in it. To view the documentation you've created, press ctrl-o in your browser, and navigate to the file doc/index.html in your lab07 directory. It's worth doing this and looking at the documentation as you try to put together your pieces into the complete working program.

Submit the lab

WARNING! You are limited to 5 submissions for this lab. You will be graded on your final submission, so make sure you have thoroughly tested it before uploading!

From your lab07 directory, submit the lab with this command:

~/bin/submit -c=IC211 -p=Lab07 *.java

Don't worry about submitting the javadoc output. It can be generated by your instructor from your source code.