Sample of an input script

Assignment Help Basic Computer Science
Reference no: EM131953615

Suppose you buy 100 shares of a stock at $12 per share, then another 100 at $10 per share, then you sell 150 shares at $15. You have to pay taxes on the gain, but exactly what is the gain? In the United States, the FIFO rule holds: You first sell all shares of the first batch for a profit of $300, then 50 of the shares from the second batch, for a profit of $250, yielding a total profit of $550. Show a program that can make these calculations for arbitrary purchases and sales of shares in a portfolio. The user enters commands buy symbol quantity price, sell symbol quantity price (which causes the gain on that transaction to be displayed), and quit. Hint: Keep a Map> that manages a separate queue for each stock symbol. Additionally, add in two new choices to the menu, display which will show a list of all the stocks and how many of each are in the portfolio, and profit which would give the total of all the gains. Use the included templates. You do not need to add any additional methods other than what are included. There is a sample of an input script so you can see how I may test your program.

/* Input samples

*buy ATT 100 10

*buy APPL 10 50

*sell ATT 50 13

*buy ATT 100 15

*sell APPL 5 55

*buy GOOG 100 6

*sell APPL 5 56

*sell ATT 120 18

*sell ATT 30 20

*buy APPL 10 50

*sell GOOG 80 8

*sell GOOG 20 5

*sell APPL 10 53

*quit

 

*/

 

 

 

 

/**

  A quantity and price of a block of stocks.

*/

public class Block

{

  private final int price;

  private int quantity;

  /**

   Constructor.

   @param quantity the quantity of this block.

   @param price the price of this block.

  */

  public Block(int quantity, int price)

  {

   this.price = price;

   this.quantity = quantity;

  }

  public int getQuantity() { return quantity; }

  public int getPrice() { return price; }

  public void sell(int shares) { quantity -= shares; }

}

--------

import java.util.Scanner;

/**

  Runs a Stock Trading Simulation

*/

public class SimulationRunner

{

  public static void main(String[] args)

  {

   StockSimulator sim = new StockSimulator();

 

   Scanner in = new Scanner(System.in);

   boolean done = false;

   System.out.println("Stock Simulator Menu");

   System.out.println("-----------------------------------------------");

   System.out.println(" > buy stock-symbol quantity price");

   System.out.println(" > sell stock-symbol quantity price");

   System.out.println(" > quit to quit simulation.");

   System.out.println();

   while (!done)

   {

     System.out.print(" > ");

     String action = in.next();

     if (action.equals("buy"))

     {

      String symbol = in.next();

      int quantity = in.nextInt();

      int price = in.nextInt();

      sim.buy(symbol, quantity, price);

     }

     else if (action.equals("sell"))

     {

      String symbol = in.next();

      int quantity = in.nextInt();

      int price = in.nextInt();

      sim.sell(symbol, quantity, price);

     }

     else if (action.equals("quit"))

     {

      done = true;

     }

   }

  }

}

----------------------

import java.util.LinkedList;

import java.util.Queue;

import java.util.Map;

import java.util.TreeMap;

/**

  Class for simulating trading a single stock at varying prices.

*/

public class StockSimulator

{

  private Map<String, Queue<Block>> blocks;

 

  /**

   Constructor.

  */

  public StockSimulator()

  {

   . . .

  }

 

  /**

   Handle a user buying a given quantity of stock at a given price.

 

   @param quantity how many to buy.

   @param price the price to buy.

  */

  public void buy(String symbol, int quantity, int price)

  {

   . . .

 

  }

 

  /**

   Handle a user selling a given quantity of stock at a given price.

   @param symbol the stock to sell

   @param quantity how many to sell.

   @param price the price to sell.

  */

  public void sell(String symbol, int quantity, int price)

  {

   . . .

  }

}

Reference no: EM131953615

Questions Cloud

Calculate the external funds needed : Prepare the current balance sheet for the firm using the projected sales figure. Calculate the external funds needed.
How research paper relates to your source analysis paper : The email should include topic you wish to research, how research paper relates to your source analysis paper and any questions have for me concerning paper.
An overview of common it governance frameworks : Analyze IT strategic planning techniques : An overview of who participates in the systems acquisition process
Bank of america offering new premium credit card : Why is Bank of America offering a new premium credit card for its high-end customers? explain
Sample of an input script : Use the included templates. You do not need to add any additional methods other than what are included. There is a sample of an input script so you can see how
How much would it be willing to lend business owner : If the bank is charging customers 12% APR, how much would it be willing to lend the business owner?
What is the meaning of share value maximization : What is the meaning of share value maximization? If a firm attempts to maximize its fundamental stock price, is this good or bad for society? Explain.
Find the present value of all of the payments : This means you need to project each month's retirment withdrawl and use the NPV function to find the present value of all of the payments.
Propose two ways that a company can gain advantage : Propose two ways that a company can gain a competitive advantage over other companies when striving to recruit job applicants.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd