Question

In: Computer Science

Create a Java windows application to manage a list of stocks 1. Add a class Stock...

Create a Java windows application to manage a list of stocks

1. Add a class Stock with the following fields: companyName, pricePerShare, numberOfShares (currently owned)
and commission (this is the percent you pay a financial company when you purchase or sell stocks.

Add constructor, getters

and methods:
***purchaseShares (method that takes the number of shares purchased, updates the stock and return the cost of purchasing these shares make sure to include commission.
***sellShares (method that takes the number of shares to sell, updates the stock and return the $amount earned from the sell.
***getInvestmentAmount() is a method that returns the current value of your investments in that stock

Build the Frame layout design to allow a user to enter a stock, to save the stock to a file and to an arrayList as well.
When the program first start, check if the file exists and if so read all the stocks from the file and add them to the arrayList.

add a button to display all the stocks to a JTable

Add a necessary gui to purchase shares of the selected stock

Add necessary gui to sell shares of the selected stock
  

i use netbeans but i cant get it

Solutions

Expert Solution

StockExchange.java

  1. package com.gwt.sample.stockexchange.client;  
  2. import com.google.gwt.core.client.EntryPoint;  
  3. import com.google.gwt.event.dom.client.ClickEvent;  
  4. import com.google.gwt.event.dom.client.ClickHandler;  
  5. import com.google.gwt.user.client.ui.Button;  
  6. import com.google.gwt.user.client.ui.FlexTable;  
  7. import com.google.gwt.user.client.ui.HorizontalPanel;  
  8. import com.google.gwt.user.client.ui.Label;  
  9. import com.google.gwt.user.client.ui.TextBox;  
  10. import com.google.gwt.user.client.ui.VerticalPanel;  
  11. import com.google.gwt.user.client.ui.RootPanel;  
  12. import com.google.gwt.event.dom.client.KeyCodes;  
  13. import com.google.gwt.event.dom.client.KeyDownEvent;  
  14. import com.google.gwt.event.dom.client.KeyDownHandler;  
  15. import com.google.gwt.user.client.Window;  
  16. import java.util.ArrayList;  
  17. import com.google.gwt.user.client.Timer;  
  18. import com.google.gwt.user.client.Random;  
  19. import com.google.gwt.i18n.client.NumberFormat;  
  20. import com.google.gwt.i18n.client.DateTimeFormat;  
  21. import java.util.Date;  
  22. /**
  23. * Entry point classes define <code>onModuleLoad()</code>.
  24. */  
  25. public class StockExchange implements EntryPoint {  
  26.       private VerticalPanel mainPanel = new VerticalPanel();  
  27.       private FlexTable stocksFlexTable = new FlexTable();  
  28.       private HorizontalPanel addPanel = new HorizontalPanel();  
  29.       private TextBox newSymbolTextBox = new TextBox();  
  30.       private Button addStockButton = new Button("Add");  
  31.       private Label lastUpdatedLabel = new Label();  
  32.       private ArrayList<String> stocks = new ArrayList<String>();  
  33.       private static final int REFRESH_INTERVAL = 5000; // m  
  34.     /**
  35.      * This is the entry point method.
  36.      */  
  37.     public void onModuleLoad() {  
  38.         stocksFlexTable.setText(0, 0, "Symbol");  
  39.         stocksFlexTable.setText(0, 1, "Price");  
  40.         stocksFlexTable.setText(0, 2, "Change");  
  41.         stocksFlexTable.setText(0, 3, "Remove");  
  42.      // Assemble Add Stock panel.  
  43.         addPanel.add(newSymbolTextBox);  
  44.         addPanel.add(addStockButton);  
  45.         // Assemble Main panel.  
  46.         mainPanel.add(stocksFlexTable);  
  47.         mainPanel.add(addPanel);  
  48.         mainPanel.add(lastUpdatedLabel);  
  49.      // Associate the Main panel with the HTML host page.  
  50.         RootPanel.get("stockList").add(mainPanel);  
  51.      // Move cursor focus to the input box.  
  52.         newSymbolTextBox.setFocus(true);  
  53.         // Setup timer to refresh list automatically.  
  54.           Timer refreshTimer = new Timer() {  
  55.             @Override  
  56.             public void run() {  
  57.               refreshWatchList();  
  58.             }  
  59.           };  
  60.           refreshTimer.scheduleRepeating(REFRESH_INTERVAL)  
  61.         // Listen for mouse events on the Add button.  
  62.         addStockButton.addClickHandler(new ClickHandler() {  
  63.           public void onClick(ClickEvent event) {  
  64.             addStock();  
  65.           }  
  66.         });  
  67.         // Listen for keyboard events in the input box.  
  68.           newSymbolTextBox.addKeyDownHandler(new KeyDownHandler() {  
  69.             public void onKeyDown(KeyDownEvent event) {  
  70.               if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {  
  71.                 addStock();  
  72.               }  
  73.             }  
  74.           });  
  75.       }  
  76.       /**
  77.        * Add stock to FlexTable. Executed when the user clicks the addStockButton or
  78.        * presses enter in the newSymbolTextBox.
  79.        */  
  80.       private void addStock() {  
  81.           final String symbol = newSymbolTextBox.getText().toUpperCase().trim();  
  82.           newSymbolTextBox.setFocus(true);  
  83.           // Stock code must be between 1 and 10 chars that are numbers, letters, or dots.  
  84.           if (!symbol.matches("^[0-9A-Z\\.]{1,10}$")) {  
  85.             Window.alert("'" + symbol + "' is not a valid symbol.");  
  86.             newSymbolTextBox.selectAll();  
  87.             return;  
  88.           }  
  89.           newSymbolTextBox.setText("");  
  90.        // Don't add the stock if it's already in the table.  
  91.           if (stocks.contains(symbol))  
  92.             return;  
  93.        // Add the stock to the table.  
  94.           int row = stocksFlexTable.getRowCount();  
  95.           stocks.add(symbol);  
  96.           stocksFlexTable.setText(row, 0, symbol);  
  97.        // Add a button to remove this stock from the table.  
  98.           Button removeStockButton = new Button("x");  
  99.           removeStockButton.addClickHandler(new ClickHandler() {  
  100.             public void onClick(ClickEvent event) {  
  101.               int removedIndex = stocks.indexOf(symbol);  
  102.               stocks.remove(removedIndex);  
  103.               stocksFlexTable.removeRow(removedIndex + 1);  
  104.             }  
  105.           });  
  106.           stocksFlexTable.setWidget(row, 3, removeStockButton);  
  107.           // Get the stock price.  
  108.           refreshWatchList();  
  109.         }  
  110.       private void refreshWatchList() {  
  111.              final double MAX_PRICE = 100.0; // $100.00  
  112.              final double MAX_PRICE_CHANGE = 0.02; // +/- 2%  
  113.              StockPrice[] prices = new StockPrice[stocks.size()];  
  114.              for (int i = 0; i < stocks.size(); i++) {  
  115.                double price = Random.nextDouble() * MAX_PRICE;  
  116.                double change = price * MAX_PRICE_CHANGE  
  117.                    * (Random.nextDouble() * 2.0 - 1.0);  
  118.                prices[i] = new StockPrice(stocks.get(i), price, change);  
  119.              }  
  120.              updateTable(prices);  
  121.             }  
  122.       private void updateTable(StockPrice[] prices) {  
  123.           for (int i = 0; i < prices.length; i++) {  
  124.                 updateTable(prices[i]);  
  125.               }  
  126.         // Display timestamp showing last refresh.  
  127.           DateTimeFormat dateFormat = DateTimeFormat.getFormat(  
  128.             DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM);  
  129.           lastUpdatedLabel.setText("Last update : "   
  130.             + dateFormat.format(new Date()));  
  131.         }  
  132.       private void updateTable(StockPrice price) {  
  133.              // Make sure the stock is still in the stock table.  
  134.              if (!stocks.contains(price.getSymbol())) {  
  135.                return;  
  136.              }  
  137.              int row = stocks.indexOf(price.getSymbol()) + 1;  
  138.              // Format the data in the Price and Change fields.  
  139.              String priceText = NumberFormat.getFormat("#,##0.00").format(  
  140.                  price.getPrice());  
  141.              NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");  
  142.              String changeText = changeFormat.format(price.getChange());  
  143.              String changePercentText = changeFormat.format(price.getChangePercent());  
  144.              // Populate the Price and Change fields with new data.  
  145.              stocksFlexTable.setText(row, 1, priceText);  
  146.              stocksFlexTable.setText(row, 2, changeText + " (" + changePercentText  
  147.                  + "%)");  
  148.             }  
  149. }

stockprice.java

  1. package com.gwt.sample.stockexchange.client;  
  2. public class StockPrice {  
  3.   private String symbol;  
  4.   private double price;  
  5.   private double change;  
  6.   public StockPrice() {  
  7.   }  
  8.   public StockPrice(String symbol, double price, double change) {  
  9.     this.symbol = symbol;  
  10.     this.price = price;  
  11.     this.change = change;  
  12.   }  
  13.   public String getSymbol() {  
  14.     return this.symbol;  
  15.   }  
  16.   public double getPrice() {  
  17.     return this.price;  
  18.   }  
  19.   public double getChange() {  
  20.     return this.change;  
  21.   }  
  22.   public double getChangePercent() {  
  23.     return 10.0 * this.change / this.price;  
  24.   }  
  25.   public void setSymbol(String symbol) {  
  26.     this.symbol = symbol;  
  27.   }  
  28.   public void setPrice(double price) {  
  29.     this.price = price;  
  30.   }  
  31.   public void setChange(double change) {  
  32.     this.change = change;  
  33.   }  

}  

StockExchange.gwt.xml

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!--  
  3.   When updating your version of GWT, you should also update this DTD reference,  
  4.   so that your app can take advantage of the latest GWT module capabilities.  
  5. -->  
  6. <!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"  
  7.   "http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">  
  8. <module rename-to='stockexchange'>  
  9.   <!-- Inherit the core Web Toolkit stuff.  -->  
  10.   <inherits name='com.google.gwt.user.User'/>  
  11.   <!-- Inherit the default GWT style sheet.  You can change   -->  
  12.   <!-- the theme of your GWT application by uncommenting    -->  
  13.   <!-- any one of the following lines. -->  
  14.   <inherits name='com.google.gwt.user.theme.clean.Clean'/>  
  15.   <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->  
  16.   <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->  
  17.   <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->  
  18.   <!-- Other module inherits   -->  
  19.   <!-- Specify the app entry point class.   -->  
  20.   <entry-point class='com.gwt.sample.stockexchange.client.StockExchange'/>  
  21.   <!-- Specify the paths for translatable code -->  
  22.   <source path='client'/>  
  23.   <source path='shared'/>  
  24.   <!-- allow Super Dev Mode -->  
  25.   <add-linker name="xsiframe"/>  
  26. </module>  

Related Solutions

***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates...
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: • Number of days on the trip • Amount of airfare, if any • Amount of car rental fees, if any • Number of miles driven, if a private vehicle was used • Amount of parking fees, if any • Amount of...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class,...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. -Add a method addToCollection. In this method, add one to collected...
Write a Java program to process the information for a bank customer.  Create a class to manage...
Write a Java program to process the information for a bank customer.  Create a class to manage an account, include the necessary data members and methods as necessary.  Develop a tester class to create an object and test all methods and print the info for 1 customer.  Your program must be able to read a record from keyboard, calculate the bonus and print the details to the monitor.  Bonus is 2% per year of deposit, if the amount is on deposit for 5 years...
Must be in C#: 7. E-MAIL ADDRESS BOOK Create a Windows Forms Application with a class...
Must be in C#: 7. E-MAIL ADDRESS BOOK Create a Windows Forms Application with a class named PersonEntry. The PersonEntry class should have properties for a person’s name, e-mail address, and phone number. Also, create a text file that contains the names, e-mail addresses, and phone numbers for at least five people. When the application starts, it should read the data from the file and create a PersonEntry object for each person’s data. The PersonEntry objects should be added to...
JAVA PROJECT Step 1: Create an application named YourInitials_Project 3 that uses a class to convert...
JAVA PROJECT Step 1: Create an application named YourInitials_Project 3 that uses a class to convert number grades to letter grades and another class for data validation. Make comments including your name, date, and project name as well as appropriate comments throughout your application that include the step number. Step 2: Create code to print Titles Step 3: Create a variable to hold user’s choice. Remember that all variables must begin with your initials and should be descriptive. Step 4:...
java code Add the following methods to the LinkedQueue class, and create a test driver for...
java code Add the following methods to the LinkedQueue class, and create a test driver for each to show that they work correctly. In order to practice your linked list cod- ing skills, code each of these methods by accessing the internal variables of the LinkedQueue, not by calling the previously de?ined public methods of the class. String toString() creates and returns a string that correctly represents the current queue. Such a method could prove useful for testing and debugging...
Java the goal is to create a list class that uses an array to implement the...
Java the goal is to create a list class that uses an array to implement the interface below. I'm having trouble figuring out the remove(T element) and set(int index, T element). I haven't added any custom methods other than a simple expand method that doubles the size by 2. I would prefer it if you did not use any other custom methods. Please use Java Generics, Thank you. import java.util.*; /** * Interface for an Iterable, Indexed, Unsorted List ADT....
Create an Java application that uses a class to convert number grades to letter grades and...
Create an Java application that uses a class to convert number grades to letter grades and another class for data validation. Specifications The Grade class should have only one Instance Variable of type int. Use a class named Grade to store the data for each grade. This class should include these three methods:   public void setNumber(int number)   public int getNumber()   public String getLetter() The Grade class should have two constructors. The first one should accept no parameters and set the...
C# windows application form. Create a base class to store characteristics about a loan. Include customer...
C# windows application form. Create a base class to store characteristics about a loan. Include customer details in the Loan base class such as name, loan number, and amount of loan. Define subclasses of auto loan and home loan. Include unique characteristics in the derived classes. For example you might include details about the specific auto in the auto loan class and details about the home in the home loan class. Create a presentation class to test your design by...
Create the following java program with class list that outputs: //output List Empty List Empty List...
Create the following java program with class list that outputs: //output List Empty List Empty List Empty Item not found Item not found Item not found Original list Do or do not. There is no try. Sorted Original List Do There do is no not. or try. Front is Do Rear is try. Count is 8 Is There present? true Is Dog present? false List with junk junk Do or moremorejunk do not. There is no try. morejunk Count is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT