Homework 1 Due Wednesday January 14. Objectives: - Warm up the brain and the fingers. - Review core Java design mechanisms. - Think a little about software architecture. What to turn in: Some files Some javadoc A screenshot of 4 tickers running simultaneously in different windows. A screenshot of 8 tickers running simultaneously in the same window. Answers to the questions below. Grading Criteria for Written Component: 4: Demonstrates complete mastery of the material. 3: Demonstrates a general understanding of the material. 2. Demonstrates some understanding of the material. 1: Demonstrates some understanding of the general concepts implied by the material. 0: No demonstration of any understanding. Grading Criteria for Programming Component 4: Solution works perfectly. Output is attractive. Internal structure and implementation of the system are extremely clean. 3: Occasional problems with the implementation. Code is relatively clean. 2. Solution can be made to work in some case. Code is not very clean. 1. Solution doesn't work. Code is a mess. 0. No clear path to a viable solution, or doesn't even compile. Part 1. Architecture and Types. Consider the two source code trees that are part of this distribution: ticker1, and ticker2. a. Using the "box-and-arrow" block diagrams introduced in class, draw a picture of the architecture underlying each of the two implementations. b. Suppose you wanted to extend the program in ticker2 so that it could put up any number of ticker time series charts simultaneously. What would the system's architecture look like? c. ticker2/TimeSeriesGraph.java implements the DataSink interface in order to be used by Ticker.java. An alternative approach would be to have it subtype from some parent class that implemented the addPoint method. In this context, answer the following questions. Be specific. 1. What would need to change in TimeSeriesGraph.java? 2. What would need to change in Ticker.java? 3. Which java classes would need to be introduced? Why? 4. Which java classes could be eliminated? Why? 5. In general, what are the advantages of using the interface approach rather than inheritance? 6. In general, what are the disadvantages of using the interface approach rather than inheritance? 7. For this particular program (ticker2), which approach makes more sense, and why? 8. ticker1/Driver.java has a routine called doit which is called as in doit(tsg). 1. What is the type of tsg at the point in the code where doit is called? 2. What is the type of doit? 3. Are they the same type? If so, explain. If not, explain how it is possible to pass in an argument whose type is different than specified in the method definition. Part 2. The Trading Floor The program in ticker2 only shows the time series of one stock price as given on the command line. Eg, java Driver ../data/amazon.dat (if you're running on Windows, you'll need to use backslash instead of foreslash). On a real trading floor, we would need to open up a potentially unlimited number of ticker windows simultaneously, and within each, show a separate time series. The windows would of course move along in lock step. Each window should display the name of the stock in the upper right hand corner. a. Using box-and-arrow notation, show the architecture for a system that can display an arbitrary number of tickers simultaneously. b. Implement your architecture by making the appropriate changes to the code in ticker2. c. Test your system by creating similarly sized historical data sets for the stock price of a dozen or so of your favorite stocks. Yahoo offers historical stock prices for securities. I recommend that you follow the pattern used for the amazon data in the homework distribution -- that is, put each series into its own file, and then have the program access the data from the files. You'll probably find it easiest to specify the data files directly on the command line. d. Modify your program so that if invoked with the '-line' argument, time series points are connected by a line, rather than an isolated point. Example: java Driver -line ../data/amazon.dat e. Modify your program so that if invoked with the command line argument '-single' all the tickers are placed on the same graph, with each ticker having a different color. Example: java Driver -single ../data/amazon.dat ../data/msft.dat FAQ Q:Where can I find a sample data file? A:There's a datafile in data/amazon.dat Q:Why aren't you giving us all the data files we need? A:Finding and cleaning your own data files is part of this assignment. Q: How do I know if my time series graph is correct? A: You can eyeball it, or you can build a version of the ticker that generates a time series according to a known function for testing purposes. Q: Do I need to worry about malformed input in my time series data file? A: Not for this assignment. Assume that the data file is well formed. Q: We didn't cover inheritance or interfaces or... in 142. How am I supposed to do this assignment? A: The textbook covers these issues. And, of course, there's google. Q: Javac (or java) can't find the uwcse.jar file. What should I do? A: It's probably a problem with your classpath. You'll need to make sure that your classpath includes the uwcse.jar file. Q: There's a lot of detail not specified in the instructions (for example, what colors to make the lines, where to display the name of the input set, etc). How should I decide what to do? A: Use your good judgement. Q: When I run the code you distributed, I get an empty canvas. No points show up. How come? A: There are a couple of different versions of the uwcse graphics library floating around. Some of them are buggy in that if you ask them to draw a line having identical starting and ending points, you get nothing (thus interpreting a single pointed line to be a zero length line). If you find this to be the case with your version, change the call to the Line constructor so that a single point is represented by a line having two points of distance 1 from one another.