CISC 3115

Project 2: Swing

Introduction

We've done some small Swing applications together (plus Exercise 4); in this project, you'll write a slightly more complex application that includes some customized components. No-one is going to mistake this for a "real" application, but by the time you're done, you'll have a pretty solid understanding of many aspects of Swing.

Essentially, you're going to write an application that displays a list of real estate sales and then lets the user "filter" those sales to see the total value of sales by date range.

This is intended to be challenging but doable. DO NOT HESITATE to ask me questions! And DO NOT WAIT to start on this!

Phase One

So, first, write a relatively simple class called RealEstateSale. It contains three instance variables:

Note that once an object like this is created, it shouldn't be changed. So, you should write constructors and getters, but no setters. Most of the work is in the constructors: you should make sure all three elements are valid. Here is a utility class I'm providing for this project. CurrencyConverter.countryCodes is a list of all the country codes the JRE knows about; you can use this to test validity. To create a Date object, we use a Calendar object (both in java.util):

Calendar dateMaker = Calendar.getInstance();
dateMaker.set(2019, 3, 15);
Date today = dateMaker.getTime();
Note that today represents April 15— months are counted from 0. Your RealEstateSale constructor(s) should set countryCode to null if any of the parameters it receives are invalid. (And you should probably check those values for validity before passing them to the constructor, when possible.)

Phase Two

Now incorporate this class into a Swing application. First, using techniques from Exercise 4, create a JList that displays the list of sales (of course, you'll have to create that list of sales, too! Be sure your data includes at least 10 sales in a variety of countries from a decent range of dates). Each sale should be displayed as a string containing the relevant info; something like

US | November 4, 1984 | 20,000
You can use Java to help you format the date nicely:
 DateFormat localDateFormat = DateFormat.getDateInstance();
 String dateString = df.format(today);

Phase Three

Once you have your sale-displaying list working, turn your attention to displaying the total value of the sales. Probably you can use a simple JLabel to display this (remember we can call setText() to change the text it displays). First, get this working assuming that all the sale prices are given in dollars. Once you have that logic working, use the CurrencyConverter.currConvert() and CurrencyConverter.getCurrency()methods I provide to convert the sale prices from the local currency to US dollars (country code US). (Note there's a small problem here: the method I provide uses the current exchange rate, but for sales in the past, it would probably be better to use the exchange rate from the date of the sale! But don't worry about that for now.)

Finally, add controls that will allow the user to specify the date range of the sales whose values are summed for display (so e.g. you could ask for the total sales between January 1 and December 31, 2015). The easiest way to do this is with a JSpinner, which has support in the API for working with dates. In particular, if you have Date values firstDate and lastDate, then you can create a JSpinner that lets the user select dates between those ranges like this:

SpinnerDateModel model = new SpinnerDateModel(firstDate,              // date initially displayed
                                              firstDate,              // low date in spinner's range
                                              lastDate,               // high date in spinner's range
                                              Calendar.DAY_OF_MONTH); // increment target
JSpinner spinner = new JSpinner(model);
Note that the first parameter sets the value that is initially displayed by the spinner; the last parameter specifies which part of the date is incremented by the spinner's controls.

Also note that these spinners should not change what is displayed in the JList. They should only affect the displayed sum of sale values.

Turning in and Grading

Be sure the class containing main() is called ProjectTwo. To turn in your project, send me a zipfile containing all the Java source files you created, as well as CurrencyConverter.java. The zipfile must be named LastnameFirstnameProject2.zip (that is, if I were submitting this, I would send DexterScottProject2.zip. Do not send a file that has been compressed with gzip, RAR, or any other archive/compression format. If you prefer, you may store your zipfile with a cloud service and send me a link.

Your grade will be based on the following elements (see Project 1 for notes about style and documentation):

  25%  Compiles and runs
  25%  Runs correctly
  10%  Layout is usable. (Clear and understandable, but not fancy)
  20%  Good/readable style (follows guidelines)
  20%  Appropriate comments

Your email to me must be datestamped by 6:00pm, Wednesday, May 1. (Three weeks from the date of assignment, though including the holiday week.) Remember that I don't generally accept late assignments. But I'm happy to receive your work well in advance of the deadline.

Extra Credit Possibilities

There are lots of behaviors you can add for fun, if you have the time and inclination. Adding some or all of these will add up to 10 points (out of 100) to your score for this project.

Other additions are certainly possible, but please check with me about their "extra-creditworthiness" before you implement them.