CSCI 470/680E - Assignment 5 - Fall 2009

50 points

For this assignment you will write a simple console mode client that will communicate via Sockets with a server running on turing.cs.niu.edu.

The server has already been written and will be running on port 9700.  It communicates using lines of text (println() of the PrintWriter class and readLine() of the BufferedReader class).

This client-server pair will enable a user to request current stock quotations from the server, which will (pretend to) look up the current value requested and then send the time, date, and current quotation value back to the client, which will then display it.

Here is a typical client session:

Connected to turing.cs.niu.edu/111.222.333.444
Enter Stock Index Request
D)ow Jones Industrial Average
N)ASDAQ Average
S)tandard and Poor Index
Q)uit
d
Mon March 23 12:57:12 CDT 2009
Dow Jones Average 7983.34
... more requests...
Another (y/n)
n
Dow Low:     xxxxxx.xx   Dow High      mmmm.mm
NASDAQ Low:    yyyy.yy   NASDAQ High:  zzzz.zz
S&P Low:        aaa.aa   S&P High:      bbb.bb

The data in the first output line ("Connected to...") should be the result of calling the InetAddress class's static getByName() method.

The 'd' and the 'n' are from the user; the two lines with date/time and the stock quote are from the server.

The server expects a request from the client to consist of a String with single character: d, n, s, or q (upper or lower case).

The server sends the date/time formatted as shown above.  You do not need to do anything except display it.  However, only the numeric value of the answer (formatted to 2 decimal places) is sent to the client.  It does not send the value's label  (e.g. "Dow Jones Average" in the example above).

The server sends the date/time and the string "invalid request" if the user enters something other than d, n, s, or q (upper or lower case).

The last 3 lines should report high and low values of each of the three funds' values reported while the program was running.  You may set initial low values at 100000 and initial high values to 0.  If no requests are made to a specific fund, then these initial high/low values will be reported.

Investigate and use the Java Formatter class which has methods to use printf()-like syntax to format and display output, so that the numbers and labels line up as shown above.  Make sure there is room for at least 100000.00.

That's it.  The code for this is less than 150 lines.