Buying/Selling Shares of Stocks Buying and selling shares of stocks of listed companies is a typical task to do among investors. Of course, this would result in a capital gain (or loss) when the shares are sold. This is computed as the difference between the shares' selling price and the price was originally paid to buy it. When an investor has a single share of stock, the process is easy. However, when (s)he sells multiple shares of stocks, bought over a period of time and possibly with different prices, the first step is to identify which shares of stocks are to be sold. There are two accounting principles (protocols) that are followed depends on the market of stocks: the shares bought last to be sold first, and the other is to sell the shares that stayed the longest. You are required to implement a program to calculate the possible capital gain/loss using these two protocols. This would facilitate the process for investors to know which market to go for and invest their money in. As an example, suppose investor A bought the following shares from company X as follows: 130 shares at $30 each on 1 March 20 shares at $35 each on 5 March 50 shares at $40 each of 10 March and he sold: 100 shares at $35 each on 15 March Applying the first principle (i.e., FIFO) means that the 100 shares would be sold from the 130 shares that he bought on March 1*. Thus, the capital gain would be 100 * $5 = $500, where $5 is the difference in price between the original price when bought and when sold. On the other hand, by applying the second principle (i.e., LIFO), that means the capital gain is (50 * -$5) + (20 * $0) + (30 * $5) = -250 + 0 + 150 = -$100. In this project you need to build a Java graphical user interface using javaFX and include the following functions: Function 0: to select the accounting principle: A. Sell old shares first B. Sell new shares first Function 1: this function will read a file that, if exists, will contain the currently held shares of the investor: the number of shares, their buying dates, and the price of a single shares at the purchase time, and the name of the company the shares belong to. The name of the file is (shares.txt) and the input file format is specified as follows: Number of shares, Price per share, Company, Date Note: the file is sorted by date (oldest first). According to the selected accounting principle in function 1, you need to store the data in a Stack or Queue. (i.e., if you choose A, you need to store the data in a linked Queue. if you choose B, you need to store the data in a linked Stack.) Function 2: this function will allow the user to buy new shares by specifying the number of shares to buy, and the name of the company the shares belong to. The daily price found in a file named "dailyprice.txt". The shares entered should be updated and added to the shares currently held in the queue or the stack. Function 3: this function will allow the user to sell shares of stocks using any of the two principles (i.e., A or . Once the information (i.e., number of shares to sell, and the name of the company the shares belong to) has been entered, the list of currently held shares should be updated, and the total capital gain/loss should be updated. Note: capital gain/loss starts with 0; Once the shares are sold, you should display the details of how the shares where profit/loss is encountered. Of course, you have to specify the company you are selling their shares and apply the logic only to its shares. Function 4: this function will print the total capital gain/loss from all transactions that took place in that session. Function 5: to store the currently held shares back to the transactions file "shares.txt". You may not use Arrays or ArrayList

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Solve in Java
Buying/Selling Shares of Stocks Buying and selling shares of stocks of listed companies is a typical task to do among investors. Of course, this would result in a capital gain (or loss) when the shares are sold. This is computed as the difference between the shares' selling price and the price was originally paid to buy it. When an investor has a single share of stock, the process is easy. However, when (s)he sells multiple shares of stocks, bought over a period of time and possibly with different prices, the first step is to identify which shares of stocks are to be sold. There are two accounting principles (protocols) that are followed depends on the market of stocks: the shares bought last to be sold first, and the other is to sell the shares that stayed the longest. You are required to implement a program to calculate the possible capital gain/loss using these two protocols. This would facilitate the process for investors to know which market to go for and invest their money in. As an example, suppose investor A bought the following shares from company X as follows: 130 shares at $30 each on 1 March 20 shares at $35 each on 5 March 50 shares at $40 each of 10 March and he sold: 100 shares at $35 each on 15 March Applying the first principle (i.e., FIFO) means that the 100 shares would be sold from the 130 shares that he bought on March 1*. Thus, the capital gain would be 100 * $5 = $500, where $5 is the difference in price between the original price when bought and when sold. On the other hand, by applying the second principle (i.e., LIFO), that means the capital gain is (50 * -$5) + (20 * $0) + (30 * $5) = -250 + 0 + 150 = -$100. In this project you need to build a Java graphical user interface using javaFX and include the following functions: Function 0: to select the accounting principle: A. Sell old shares first B. Sell new shares first Function 1: this function will read a file that, if exists, will contain the currently held shares of the investor: the number of shares, their buying dates, and the price of a single shares at the purchase time, and the name of the company the shares belong to. The name of the file is (shares.txt) and the input file format is specified as follows: Number of shares, Price per share, Company, Date Note: the file is sorted by date (oldest first). According to the selected accounting principle in function 1, you need to store the data in a Stack or Queue. (i.e., if you choose A, you need to store the data in a linked Queue. if you choose B, you need to store the data in a linked Stack.) Function 2: this function will allow the user to buy new shares by specifying the number of shares to buy, and the name of the company the shares belong to. The daily price found in a file named "dailyprice.txt". The shares entered should be updated and added to the shares currently held in the queue or the stack. Function 3: this function will allow the user to sell shares of stocks using any of the two principles (i.e., A or . Once the information (i.e., number of shares to sell, and the name of the company the shares belong to) has been entered, the list of currently held shares should be updated, and the total capital gain/loss should be updated. Note: capital gain/loss starts with 0; Once the shares are sold, you should display the details of how the shares where profit/loss is encountered. Of course, you have to specify the company you are selling their shares and apply the logic only to its shares. Function 4: this function will print the total capital gain/loss from all transactions that took place in that session. Function 5: to store the currently held shares back to the transactions file "shares.txt". You may not use Arrays or ArrayList

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education