This project consists of a Java program that is intended to solve the problem of calculating the number of days between two supplied dates that was posed as problem #1 in the ThoughtWorks coding test. The primary entry class is the Dates wrapper class. All intended uses of this program can be accessed via the Dates class. The working code is in the MyDate class and the BadDateException class. Test code resides in the TestMyDate class.
The quickest way to get started is to follow these steps:
java -classpath %classpath%com.markcrocker.thoughtworks.jar com.markcrocker.thoughtworks.Dates -h
This has some disadvantages, such as not having access to the source code and documentation that is included in the jar file. A more reasonable way to get started is:
java com.markcrocker.thoughtworks.Dates -h
Both cases assumes that your java executable is
java. Some operating systems require the use of
JRE or some other executable to start java programs.
See your system documentation for details.
%classpath% would be
$classpath; in UNIX or something else in other
operating systems. Again, see the documentation for your
The unjar operation can usually be accomplished with
unjar com.markcrocker.thoughtworks or
com.markcrocker.thoughtworks depending on your OS.
There are a few points that are worth noting. There is a sample input file included with the distribution. To use it, type something like:
java com.markcrocker.thoughtworks.Dates -f com/markcrocker/thoughtworks/testFile.txt
Command line forms can be used multiple times. For example something like:
java com.markcrocker.thoughtworks.Dates -h 6, 2, 1983 6, 22, 1983 -t 7, 4, 1984, 12, 25, 1984 1, 3, 1989, 8, 3, 1983
is a perfectly acceptable input. Note that between the second last pair of dates and the last pair of dates, there is no comma after the year "1984". This is optional. The command line input parsing method works with or without a comma after the year. All other commas are required. Spaces between tokens are required as well. Additional spaces are optional. Multiple switches are allowed, but they each require a separate space and "-". So
-h -t -e works fine, but the UNIX
-hte does not work.
The HTML "fontified" source code is available from:
The raw java source code can be found in the source subdirectory.
The top level of the Javadocs for this package is available from packages.html.
I do not consider this project entirely finished. However, I have released the project for the following reasons:
There were LOTS of other features that I wanted to add to this project. I generally try to avoid the temptation to fall in to the trap of "creeping elegance", but this was a test that was supposed to illustrate my programming abilities and I got very little response from my customers regarding feature requirements beyond what was in the original requirements. Consequently, I did add a number of features, such as syntax message, multiple input methods and parsing that allows multiple data sets on one line. Other features that I was working on can be seen in the "todo" comments at the bottom of the source code files (eg: Dates todos). If you are interested in seeing any of these extras added to the package, please let me know. I would love the excuse to do some of these.
Since this is a test and there were three options, you might be wondering why I chose to do the Dates problem especially when it seems to be the easiest question of the three. Normally, I would've picked the most difficult of the group to demonstrate my abilities as thoroughly as possible. However, the Dates problem peaked my interest because I've encountered a number of tricky date related issues in my past Perl programming experience (see Dates.pl example) and wanted to explore the Java solutions to these problems. Also, my earlier foray into Java's Date class indicated that most of the Date class is now deprecated and I wanted to explore its' replacement, the Calendar class. Naturally, the requirements of the test prohibited the use of the Date or Calendar classes, but I did use this as an excuse to learn more about them. None of the code I developed during that learning process is included in this release of this project.
Mark Crocker's home page is available at:
This page last updated 2000-Sep-01 08:34 MDT (Friday) by Mark Crocker
Comments or Suggestions? email: email@example.com
Copyright© 2000, Mark Crocker All rights reserved.