newton 2.0
CPS 132, Program #5 – Stock Tracker
NOTE: See the Bluej project “finance-test” on Isidore to review how to use the Yahoo Finance API. This example was discussed in class on 11/29.
For this assignment, you will build and add functionality to a simple GUI. You will use GUIGenie to create the basic GUI app. Then you will copy that code into a Bluej project to add the functionality.
The app you are creating will keep track of the current share prices of a list of stocks. The GUI you design should coontain all the needed components to later provide the following:
• Allow the user to add a stock to the list, by providing the appropriate stock symbol. • Allow the user to remove a stock from the list, by providing the appropriate stock symbol. • Provide a text area big enough to display at least 10 lines of text, each as large as 50 characters, one line
for each stock that includes the following information: ◦ the stock symbol ◦ the stock price ◦ the company name
• Any time a stock is added or removed from the list, the entire list in the text area should be refreshed, reflecting the current price for each stock in the list.
• A label field that can be used to provide error messages while processing requests. (Initially should contain the empty string.)
• Allow the user to request a refresh of the list to reflect current prices.
Part I (12points)
For this part, simply design the GUI using GUIGenie. Copy that code into a Bluej project and make sure the GUI displays properly. Your GUI should include components that can later provide all the functionality listed above.
You can accomplish all of this using the GUI components we are already familiar with (JLabel, JtextField, JtextArea, Jbutton), though you are free to explore other components if you'd like.
Part II (18 points)
Next, add the following functionality to the GUI:
• The ability to add a stock to the list and refresh the list with current pricing. Display an error message is there is a problem with the stock symbol provided, or if the stock symbol is already in the list.
• The ability to remove a stock from the list and refresh the list with current pricing. Display an error message if the symbol provided is not currently in the list.
• The ability to refresh the list on request.
NOTE: You must use a Vector of strings to hold the list of stock symbols.
Extra Credit! (3 points)
Figure out how to maintain the list of stocks in alphabetic order.
What to Submit:
Create a zip file from your Bluej project folder. Upload the zip file to Isidore.
You may should some or all of the following methods available in various classes to be useful:
Vector Methods
add(item) – Add an item to the end of the vector.
add(position, item) – Add an item at the position provided. All other items will be moved further down to make room.
remove(position) – Removes the item at the position provided.
remove(item) – Searches the vector for the given item. The first occurrence found is removed. True is returned if the item is found, otherwise false is returned.
indexOf(item) – Searches the vector for an item and returns the position of the first occurrence of that item (or -1 if the item is not found).
JLabel, JTextField, JTextArea Methods
getText() - Returns a string containing all the text currently in the component.
setText(string) – Given a string, sets the text in the component to the string provided.
append(string) – (JtextArea only) will append the text provided to the text already in the component. (Remember that the special character “\n” can be used in a string to end the current line of text.)
GUI Reminders
Remember to include “implements ActionListener” in the signature for your GUI class (named “MyPanel” by default, but you can change that if you'd like).
The also remember that your GUI class needs to have the following method:
public void actionPerformed() {…}
Lastly, remember that you need to add an action listener to every button you want your program to respond to.
See any of our GUI example programs for clarification of these steps.