To simplify the testing process within your java program, please implement a dialog that asks a user
Fantastic news! We've Found the answer you've been seeking!
Question:
To simplify the testing process within your java program, please implement a dialog that asks a user to input action (buy or sell) first, then asks the user to enter shares and price. The program should allow the user to buy multiple times. The program should also terminate when a “sell” order is processed.
Transcribed Image Text:
P-5.5 When a share of common stock of some company is sold, the capital gain (or, sometimes, loss) is the difference between the share's selling price and the price originally paid to buy it. This rule is easy to under- stand for a single share, but if we sell multiple shares of stock bought over a long period of time, then we must identify the shares actually be- ing sold. A standard accounting principle for identifying which shares of a stock were sold in such a case is to use a FIFO protocol--the shares sold are the ones that have been held the longest (indeed, this is the de- fault method built into several personal finance software packages). For example, suppose we buy 100 shares at $20 each on day 1, 20 shares at $24 on day 2, 200 shares at $36 on day 3, and then sell 150 shares on day 4 at $30 each. Then applying the FIFO protocol means that of the 150 shares sold, 100 were bought on day 1, 20 were bought,on day 2, and 30 were bought on day 3. The capital gain in this case would therefore be 100 10+ 20 · 6+30 · (-6), or $940. Write a program that takes as input a sequence of transactions of the form “buy x share(s) at $y each" or "sell x share(s) at $y each," assuming that the transactions oc- cur on consecutive days and the values x and y are integers. Given this input sequence, the output should be the total capital gain (or loss) for the entire sequence, using the FIFO protocol to identify shares. P-5.5 When a share of common stock of some company is sold, the capital gain (or, sometimes, loss) is the difference between the share's selling price and the price originally paid to buy it. This rule is easy to under- stand for a single share, but if we sell multiple shares of stock bought over a long period of time, then we must identify the shares actually be- ing sold. A standard accounting principle for identifying which shares of a stock were sold in such a case is to use a FIFO protocol--the shares sold are the ones that have been held the longest (indeed, this is the de- fault method built into several personal finance software packages). For example, suppose we buy 100 shares at $20 each on day 1, 20 shares at $24 on day 2, 200 shares at $36 on day 3, and then sell 150 shares on day 4 at $30 each. Then applying the FIFO protocol means that of the 150 shares sold, 100 were bought on day 1, 20 were bought,on day 2, and 30 were bought on day 3. The capital gain in this case would therefore be 100 10+ 20 · 6+30 · (-6), or $940. Write a program that takes as input a sequence of transactions of the form “buy x share(s) at $y each" or "sell x share(s) at $y each," assuming that the transactions oc- cur on consecutive days and the values x and y are integers. Given this input sequence, the output should be the total capital gain (or loss) for the entire sequence, using the FIFO protocol to identify shares.
Expert Answer:
Answer rating: 100% (QA)
SOLUTION 1 n intinputEnter number of transactions printTotal transactions are n q capgain ... View the full answer
Related Book For
Posted Date:
Students also viewed these algorithms questions
-
A message that asks a user for input is a(n) ___________. a. Eomment b. Echo c. Prompt d. Declaration
-
Write a program that asks the user to input a vector of integers of arbitrary length. The program then counts the number of elements, the number of positive elements, and the number of negative...
-
Create a two-dimensional array to contain the three sale items for five different artists. A single array must be used to store the artist names. Allow a user to enter in a number, ranging from 1 to...
-
Determine whether the following taxpayers have gross income from the payment of their expenses: a. Julia's mother, Henrietta, is short of cash when it comes time to pay her property taxes. Julia pays...
-
A 100-acre watershed with type B soils has been commercially developed. The length of the longest flow path is 3,000 feet, and the average watershed slope is 2.5 percent. Determine the peak discharge...
-
Air enters a diffuser with a velocity of 200 m/s, a static pressure of 80 kPa and a temperature of 268 K. The velocity leaving the diffuser is 50 m/s and the static pressure at the diffuser exit is...
-
What are the main objectives of an international compensation plan? Would an integrated solution or a best-of-breed solution make more sense for a large manufacturing corporation? Do you believe that...
-
On January 3, 2014, Xenex Innovations purchased computer equipment for $125,250. The equipment will be used in research and development activities for five years or a total of 8,500 hours and then...
-
Problem #2\ Erica, Deana & Tara had average capital balances of $350,000,$380,000 and $400,000 respectively during the current fiscal year. The partnership agreement provides for an allowance of 4%...
-
Penny Stafford, the owner of Belvi Coffee and Tea Exchange, located in Bellevue, Washington, brought an antitrust suit against Starbucks. She alleged that through its exclusive leases, Starbucks bans...
-
9. Define an application program interface (API) and describe how you used an API in your AWS labs. What is the function or use case for an API? Define messaging and queuing services in AWS and...
-
What is a notable feature of the design process in lean construction? Limited collaboration Accurate estimates to minimize collaboration Planned Iterations Unidisciplinary focus
-
Simple Interest Compound Interest Formula Sheet A = Po(1+rt) r PN = Po(1 + 1) Nk k final balance - starting principal starting principal Nk d((1+)-1 -1) Annual Percentage APY = Yield Savings Annuity...
-
Using the formula for simple interest and the given values, find I. P=$600; r =8%; t = 7 years; 1=? 1=$
-
Solve 2 cos (x) - 3 cos (2)+ 1 = 0 for all solutions 0 < < 2n I =
-
If 3x +5xy = 2y, then
-
An artist who markets her paintings on social media normally sells three paintings per month, for $100 each. When she decides to lower the price to $80 each, she sells 5 paintings per month. What...
-
Find the reduced echelon form of each of the matrices given in Problems 120. c 1 26 + 4
-
Your downloadable files for Chapter 10 include a file named DEBUG10-04.jpg that contains a class diagram with syntax and/or logical errors. Examine the class diagram, and then find and correct all...
-
If a is true and b is false, then ______________. a. a AND b is true b. a AND b is false c. a OR b is false d. If a is true, then b must be true.
-
When performing a bubble sort on a list of 10 values, you can stop making passes through the list of values as soon as _____ on a single pass through the list. a. No swaps are made b. Exactly one...
-
Which managerial skill refers to the ability to view the entire situation in totality? Technical skills Human skills Conceptual skills None of the above
-
Which level of management includes departmental managers, deputy managers, and assistant managers? Strategic-level management Middle-level management Operative-level management None of the above
-
Which objective of management takes care of the conservation of the environment and natural resources? Organizational objectives Personal objectives Social objectives None of the above
Study smarter with the SolutionInn App