I’ll be away this week from June 1-5 attending the Sun JavaOne Conference in beautiful San Francisco. I plan to expand my knowledge of advanced J2EE/SOA topics as well as pick up some introductory courses on new technologies. If you want to meet up to discuss any of my recent articles, the conference, or how cold San Francisco seems to be this time of year, drop me an e-mail!
JavaRanch uses a Java program to pick the weekly winners for book promotions. It previously used a serious of classes that went the URLs, parsed the data, went to more URLs, picked some random winners and then output them to a file. These contortions were done because the old software was hard to change. With the new Java based software, we have much more active development. Time for a new approach.
Designing the new pick winners program. (It’s the 3rd iteration of the program and the 2nd I’ve done so I’m familiar with the domain.)
- Decide to make a web based version (servlet)
- Think about what I need from the database.
- Write three DAO methods to get post, topic and user info. While I wrote the integration tests first, I did write the unit tests after the code.
- Start the pick winner class Realize there is a lot of date validation logic (and determining the default week) and rename class to WinnerPickingWeek to encapsulate the date range.
- Start the pick winner class again. Call the three DAO methods tying them together.
- Now add the randomness. My test with 1 post will give me enough determinism to keep the tests passing and useful.
- Added a test for excluding ineligible winners (like Henry and I – the winner pickers)
- Now on to the front end. My servlet needs to make sure you are logged in as admin and then delegate to the processing logic.
This got a useable program that runs much faster. After that I added some jQuery logic to make the page dynamic and even more useful. But that’s another topic – possibly a more interesting one. I’ll post it later in the week.
What is interesting to me is that it gives you the answer, but not the source. For calculations, there isn’t really a source anyway. I don’t cite that 2+2=4. However, I do cite the population of Germany. So how are we supposed to know it is right? On the other hand, I think showing similar information you might not have asked for is cool.
Turns out this isn’t a big thing to worry about. WolframAlpha gives you the source of it’s answer. For example, I searched for swine flu. It told me the scientific name along with the number of cases and deaths over the last couple of days. In addition to a nice pop-up and PDF to export the data, it has a “source information” link at the bottom. This shows the data set used to derive the answer along with other resources one might be interested in.
As a source for learning, I think this is pretty cool!