Foliotracker

Índice analítico

1. Part 1: API and GUI [editar]

2. Part 2: Implementing the API [editar]

Foliotracker is an application program for tracking the value of a stock portfolio.

In the first of two parts, you'll decide on the basic functionality of your program, design a graphical user interface (GUI) for it, and specify an application programmer's interface (API) through which the GUI will access the components of the code that obtain stock quotes, maintain a database of values, and so on.

The benefit of decoupling this application into two parts (a front-end GUI and the back-end implementation) by creating a well-defined API is to allow for different types of front-end clients to access your system and use its functionality. You won't actually write any of the code that implements the API; instead you'll write a stub: a piece of code that can be used to test a client of the API, but which provides only very limited functionality. You may, for example, have the stub compute nothing and just look up values in a fixed table. This stub will allow you to assemble and test the GUI, and make sure that the functionality seems reasonable. In the second part, you'll implement the functionality of the API itself. You should not need to make any changes to the GUI or to the API.

The focus of the first part is the designing of the API and GUI implementation. You'll need to learn how to use Swing. The online Java™ Tutorial trail, which is at http://java.sun.com/docs/books/tutorial/ , includes a section on Swing and the Java Foundation Classes; you'll find it at http://java.sun.com/docs/books/tutorial/uiswing/ . The focus of the second part is the designing of the backend and its implementation. You shouldn't need to learn anything new, but will have an opportunity to refine your skills in designing with abstract data types, object models, etc. You don't need to implement the code for obtaining the stock quotes; we provide a class for you that has a simple method that takes a ticker symbol as a string and returns a price.

Part 1: API and GUI [editar]

Foliotracker enables the user to track the contents and value of multiple stock portfolios. A Foliotracker can be used to manage and maintain multiple stock portfolios where a portfolio is a collection of stock holdings. A portfolio could also contain meta-data about a person's transaction history, statistics, etc. Foliotracker discovers current stock values by querying a stock quote server across the World Wide Web. Your first task is to determine what functionality Foliotracker should support. At the minimum, it should be possible to:

  • create multiple portfolios;

  • see the positions (stock name, number of shares held, price per share, and value of the holding) in a portfolio;

  • increase and decrease the number of shares of a stock;

  • see the total value of a portfolio.

We have provided some screenshots of possible functionality. An example of a Foliotracker with multiple stock portfolios open. The user can:

  • Add a new stock to his/her portfolio.

  • Switch to another portfolio using the tab control.

  • Double-click on a stock for editing purposes.

  • Close the current portfolio.

  • Delete the current portfolio.

Figure 22.1. Foliotracker Window

Foliotracker Window

Here are some possible features you might consider including in your design:

  • saving portfolio information to disk;

  • indicating whether price is going up or down, perhaps by coloring the text or using little coloured arrows;

  • allowing the user to enter the price at which a stock was bought, to estimate gains and losses;

  • keeping track of highs and lows;

  • setting watches causing an action to occur when the stock goes up or down some amount;

  • sorting positions by value, ticker symbol, etc.

You should choose a set of features that you plan to implement. We recommend that you order them according to difficulty and desirability, and think carefully about which you will jettison if things turn out harder than you thought.

More fundamentally, you will need to consider basic questions such as

  • how portfolios will be identified (with names provided by the user?);

  • when stock prices will be updated (periodically? by explicit command?);

  • how to handle exceptional cases, such as ticker symbols that don't match stocks, or how to behave when the web site is not responding;

  • whether multiple portfolios can be shown at once;

  • whether multiple simultaneous views of the same portfolio are allowed.

These issues need to be addressed at the start; they'll be much harder to deal with if you postpone them.

In the design of the API, you will also need to resolve some basic issues. Two important ones are:

  • whether the API will be passive, in the sense that the application simply treats it as a source of information, or

  • whether it will be active, by having functionality to make periodic callbacks, for example; what types will be exposed at the interface.

Your API specification will be a complete description of the functionality of the program, ignoring only the question of how the program and user communicate via the GUI. Your GUI should be easy to use and attractive, and straightforward to build. You'll probably want to play around with Swing a bit to get a feel for how things are done and what's possible before you design it.

Part 2: Implementing the API [editar]

Your task in this part is to complete your Foliotracker by implementing the API which you defined in part 1. You will need to design the internal structure of your Foliotracker backend, and test the program as a whole. This program is difficult to test because it involves a GUI, and because the changing stock prices make it hard to do repeatable tests. So you will need to devise a reasonable testing strategy that gives you some confidence that the application works reliably, and that the stock prices and position and portfolio valuations can be trusted. You will probably want to take advantage of the programmatic interface you designed in part 1, and test the GUI separately in a more ad hoc manner.

We have provided a QuoteServer module for your convenience. If you are curious, you can look at the source code for the QuoteServer, but you should be able to make use of it using only the method QuoteServer.getLastValue("<ticker>").

[Caution]Caution

The QuoteServer.java program can be outdated, test it before begining your project. If it does not work try to find a Java progam in the Internet that can read quotes. If you have problems contact the teacher.

File QuoteServer.java.