Stock market in java

Assignment Help JAVA Programming
Reference no: EM131843273

Assignment 1: Stock market in Java

Description

A stock market is a platform that has stocks listed on it and investing accounts can use the platform to trade stocks. The current value of a stock on the market is actually the price of the last trade of that stock that occurred on the market. In order to trade stocks, investors (represented here by investing accounts) need to signal their intention to buy (make a bid) or to sell (asking for a certain price) to the stock market. Bids and asks are usually referred to as "orders".

Sending a "bid" to the stock market means that you are sending to the market information about how much of a particular stock you want to buy and what price you are willing to pay per stock. Sending an "ask" to the stock market means that you are sending to the market information about how much of a particular stock you want to sell and what price you are asking for.

The stock market, as a platform/system, has the responsibility to monitor all the bids and asks that it receives, and make transactions happen. Transactions are made if and only if, for a particular stock, there is a bid (order to buy) with a price equal or superior to an asking price (order to sell). For example, let's assume that we have a stock named COMP, and this is the list of bids and asks for this stock:

Bids:
- Account #111111: 100 of COMP at $10.50
- Account #111112: 100 of COMP at $10.20
- Account #111113: 100 of COMP at $10.10
Asks:
- Account #111114: 100 of COMP at $10.75
- Account #111115: 100 of COMP at $11.00
- Account #111116: 100 of COMP at $12.50

At this point in time, no transaction can be made, because the bids are too low (or if you look at it the other way around, the asks are too high).

Let's assume now that a new ask is sent to the system: "Account #111117: 100 of COMP at $10.40". Now the system can make a transaction, because there is a bid with a price ($10.50) >= to the price of an ask ($10.40). The price of the transaction is always going to be set to the best possible price for the last order (bid or ask) that comes in and triggers the transaction. In our example, the last offer to come in is an ask at $10.40, so the price of that transaction will be $10.50, because there was already someone in the system who was offering to buy at $10.50.

When multiple orders are received by the system at the same price, priority will always be given to the order that arrived first.

You can assume the following conditions:

1. Investing accounts can only send an ask or a bid for one particular stock once: duplicate entries are ignored.

2. Investing accounts can only send asks (orders to sell) for a particular stock if they own the stock: if the investing account does not hold the stock, the order is invalid.

3. Investing accounts can only send bids (orders to buy) for a particular stock if they can afford it: if the balance is not high enough to make the purchase (including the transaction fee), the order is invalid.

4. To make things simpler, all the orders to buy and to sell will be of the same number of stocks (100 in the above example).

5. Bids and asks stay on the system until a transaction is made, or a request to remove them is made. This means that if a particular investing account has multiple bids for different stocks on the system, and they all end up being processed, it is possible that this account will get a negative balance.

6. Each time a transaction is completed, there is a fee of $9.99 (for both accounts involved).

Actions

There are seven actions and one comment that the system should recognize. For each action, an example is given as well as a list of outcomes (what can happen as a result of the command). Your program must be able to read and process all the actions (operations) provided in a text file given as a command-line argument.

STOCK [STOCK_SYMBOL]

- This action adds a new stock to the system. It sets the initial price to 0. The bids and asks for this stocks are initially empty.
- Example: STOCK COMP
- Outcomes: CONFIRMED, DUPLICATE

- A stock is a duplicate if there is already a stock with this symbol in the system.
- The symbol is usually composed of three of four capital letters (no whitespaces).

NEW [ACCOUNT#] [BALANCE] [OWNED_STOCKS]
- This action adds a new investing account to the system.

- [ACCOUNT#] is going to be a valid int.
- [BALANCE] is going to be a valid double. It corresponds to the starting balance in the account.

- [OWNED_STOCKS] is going to be a list of triples representing all the stocks that are owned in the account. The three elements in the triple will be: (1) the stock symbol, (2) the number of stocks and (3) the price for each stock, separated by dashes (-). A whitespace separates each triple.
For example, [OWNED_STOCKS] could be: COMP-100-10.55 MATH-100-5.55
[OWNED_STOCKS] can also be empty, if the account does not hold any stock at the moment of creation.
- Example: NEW 111111 10000.10 COMP-100-10.55 MATH-100-5.55

- Outcomes: CONFIRMED, DUPLICATE, STOCK NOT FOUND
- If the investing account already exists (there is already an account with the same account number), the DUPLICATE error should be reported.
- All stocks in [OWNED_STOCKS] must already be in the system. If not, the STOCK NOT FOUND error should be reported.

ADD [ASK_OR_BID] [ACCOUNT#] [SYMBOL] [NB_STOCKS] [PRICE]
- This action adds an order (order to sell (ask) or to buy (bid)) to the system, from a specific account number (int), for a specific stock symbol (string), for a certain number of stocks (int) and for a certain price (double).
- [ASK_OR_BID] is a string and can either be "ASK" or "BID".
- Example: ADD ASK 111111 COMP 100 10.50

- Outcomes: ACCOUNT NOT FOUND, STOCK NOT FOUND, INVALID ORDER, DUPLICATE, CONFIRMED, TRANSACTION COMPLETED
- ACCOUNT NOT FOUND is used when the account number doesn't exist.
- STOCK NOT FOUND is used when the stock doesn't exist.

- INVALID ORDER is used for two different situations, depending on whether the order is an ask or a bid:
- if the order is an ask: INVALID ORDER is used when the investing account does not currently hold the stock (cannot offer to sell what you don't own).
- if the order is a bid: INVALID ORDER is used when the balance of the investing account isn't high enough to buy the stocks and cover the transaction fees.
- DUPLICATE is used when the account already has an ask or a bid order for this stock (no duplicates allowed, i.e. an investing account cannot have more than 1 ask or 1 bid for the same stock).

- CONFIRMED is used when the order is successfully added to the system.
- TRANSACTION COMPLETED is used if, after the order has been confirmed, it triggers a transaction. The system should obviously deal with the transaction at this time, which means: (1) setting the price of the transaction (following the rules described earlier), (2) adding the stocks to list of stocks owned by the buyer, (3) removing the stocks from the list of stocks owned by the previous owner, (4) updating the balances of both investing accounts, including the transaction fees and (5) removing both the bid and ask orders that triggered the transaction from the system.
REMOVE [ASK_OR_BID] [ACCOUNT#] [SYMBOL]
- This action removes an ask order from the system, for a specific account number (int) and for a specific stock symbol (string). Price and number of stocks is not necessary here, since only one ask can be in the system for each account.
- [ASK_OR_BID] is a string and can either be "ASK" or "BID".
- Example: REMOVE BID 111111 COMP

- Outcomes: ACCOUNT NOT FOUND, STOCK NOT FOUND, ORDER NOT FOUND, CONFIRMED
- ACCOUNT NOT FOUND is used when the account number doesn't exist.

- STOCK NOT FOUND is used when the stock doesn't exist.
- ORDER NOT FOUND is used when there is no order of this type (type refers to [ASK_OR_BID]) from that account for that stock.
- CONFIRMED is used when the order was successfully removed from the system.

BALANCE [ACCOUNT#]
- This action prints the status of an investing account: what is the current balance? Which stocks are owned and at what price?
- Example BALANCE 111111

- Outcomes: NOT FOUND (if the account number doesn't exist), or an output is produced.
- if an account is in the system, here is an example of an output: Account #111111 has a balance of $1500.01 and owns these stocks:
-Account #111111: 100 of COMP at $10.50.
-Account #111111: 100 of MATH at $5.55.
-Account #111111: 100 of BIO at $6.68.

STATUS [STOCK_SYMBOL]
- This action prints the status of a stock: what is the current price of the stock (based on the last trade)? What are the bids and asks for this stock?
- Example STATUS COMP

- Outcomes: NOT FOUND (if the stock doesn't exist), or an output is produced.
- If the stock is valid, here is an example of an output: Stock: COMP has a current price of $10.50.
Here is the list of bids:
-Account #111111: 100 of COMP at $10.50.
-Account #111112: 100 of COMP at $10.20.
-Account #111113: 100 of COMP at $10.10. Here is the list of asks:
-Account #111114: 100 of COMP at $10.75
-Account #111115: 100 of COMP at $11.00
-Account #111116: 100 of COMP at $12.50

QUIT
- This ends the program.

- Outcome: the program ends. The message DONE should be printed.
#

- any line that starts with # is a comment.
- example #this is a comment
- if a line is a comment, it does not affect the system in any way.

- all comments should be echoed to output.

Additional notes on the operations:

- One account can have (not more than) one bid and (not more than) one ask order for the same stock at a time. The system does not need to check before making a transaction if the buyer is the same account as the seller (so it's possible for an account to sell to itself).
- An account can hold multiple times the same stock (e.g. 100 of COMP at 9.95 and 100 of COMP at 10.55). If it is the case, you should not combine them together (e.g. no need to combine in order to get 200 of COMP at 10.25).

Input Error Checking

When the format is specified for a command, you can assume all the stated properties hold (i.e., stock symbols will all have the proper format, integers will be valid, doubles will be valid, etc.). Your code does not need to do error checking for these properties.

Data Structures

There are some restrictions on data structures you must use for the assignment. Do not use ANY built-in Java collection classes (e.g. ArrayLists, Hashes, ...) or Java Generics in this assignment: any linked structures must be your own, built from scratch. You should not use arrays other than for temporary operations (e.g., split() for strings).

Reference no: EM131843273

Questions Cloud

How many employees must be covered by cheque : How many employees (the minimum) must be covered by Cheque. Company's defined benefit pension plan for the plan to conform with ERISA?
Discuss how incentive pay plans : Discuss how incentive pay plans - both individual and group - motivate employees to achieve high levels of performance.
What are potential benefits and pitfalls of hiring someon : What are the potential benefits and pitfalls of hiring someone with Chief Johnson's style for the position at Bay Harbor? Why
Graph lynn price consumption curve for prices : Graph Lynn's Price consumption curve for prices, PC = $.60, PC = $.80, and PC = $1.10. Please put the number of cups of coffee (C) on the horizontal axis
Stock market in java : COMP 2150 - Stock market in Java - A stock market is a platform that has stocks listed on it and investing accounts can use the platform to trade stocks.
What are issues that a project consultant may face : What are issues that a Project consultant may face in terms of project shocks?
What happens to the amount of exports from canada : C. In part B, what happens to the amount of exports from Canada?
How many pounds will have to be washed at occupancy : How many 100-pound washers are needed to do the job in seven hours if each washing cycle takes about one-half hour?
How might you determine the leader of the group and why : Building a Family and social service agancy proposal, what are plans could be used to "muster support" for your agency that deals with homebased and community.

Reviews

len1843273

2/1/2018 5:13:57 AM

The easier it is to mark your assignment, the more marks you are likely to get. Do yourself a favour. Submit all files on D2L. Remember to submit your electronic honesty declaration on D2L before the assignment deadline. Evaluation - Input/output works as required: 1pt - Building your own data structures: 1pt - Each of the 7 actions (operations) work properly: 7pts (1pt each) - Transactions are processed correctly: 1pt Total: 10pts

len1843273

2/1/2018 5:13:50 AM

Submit all your source code for all classes. Each class should be declared as public in its own file. You should also submit a text document giving the output on the official test data. You MUST submit all of your files in a zip file. Additionally, you MUST follow these rules: • All of the files required for your project should be in a single directory. • Include a README.TXT file that describes exactly how to compile and run your code from the command line. The markers will be using these instructions exactly and if your code does not compile directly, you will lose marks.

len1843273

2/1/2018 5:13:37 AM

• This is a large programming problem with many pieces to the puzzle – remember your incremental development strategy from COMP1020 and get small pieces working rather than trying to tackle the whole thing at once. • Your program will be tested by the markers under Unix, and must run with a simple javac/java as per the "Running Java" instructions on the course website. Your program must read and process all the actions (operations) provided in a text file given as a command-line argument. • As yet, we do not know much OO - you should follow the rules of abstraction and object-oriented programming based on what you have learned in previous courses and given the limitations specified in this assignment. Use separate classes for entities like investing account, stock, stock market, stock order. Try to make other entities and classes for your ADTs. Do not be afraid of using many classes – breaking things up usually makes for much simpler pieces. • Official test data will be provided several days before the assignment is due.

len1843273

2/1/2018 5:13:25 AM

• Please follow both the "Programming Standards" for all work you submit. Programming standards 1-22 are in effect, but see also the notes in this assignment. • Complete the honesty declaration on D2L before the assignment submission (in Resources – Checklist). You can’t submit the assignment without completing the online honesty declaration. • Hand-in will be via the D2L Dropbox facility. Make sure you leave enough time before the deadline to ensure your hand-in works properly. The assignments are submitted using D2L’s time (not the time on your computer). Assignments that are late will be marked according to the late policy in the ROASS. • Official test data will be provided several days before the assignment due date. Until then, work with your own test data.

Write a Review

JAVA Programming Questions & Answers

  Create a class for services offered by a hair-styling salon

Create a class for services offered by a hair-styling salon. Data fields include a String to hold the service description and write an application named Salon Report that contains an array to hold six Service objects and fill it with the data

  Analyze a task and describe it succinctly

Programming the Familiar Good programmers are able to analyze a task and describe it succinctly, accurately, and unambiguously. Even tasks that you perform without much thought are surprisingly complex when you stop and consider all of their compo..

  Write a graphical user interface class

Write a graphical user interface class called SentenceCounterGUI. It should be able to manipulate the sentence of words and have the behaviour label.

  Create a non-gui based java application

Create a non-GUI based Java application that calculates weekly pay for an employee. The application should display text that requests the user input the name of the employee.

  Create appropriate packages for all classes

Requirements listed using Java programming code only. You must use the concepts we work on in class. All code must be fully commented

  Create java application that implements use of an int array

Create a Java application that implements use of an int array. Use for loops to iterate through the array using the array's length variable to stay

  Learn how expressions can be evaluated at run-time

Write a Java program (a collection of Java classes) including a class named ExpressionCalculator that contains a static main method. This main method will prompt the user to enter a constant expression.

  Create a screen shot of the interactive session output

Create a Java program according to the specifications. Create a screen shot of the interactive session output, and include a description of your Java program.

  Provide two reasons why internet has a problemistic future

How will the Internet impact the future of politics and businesses practices?

  Statistics list program

You will also modify your program to accept input from an input file and print a report to an output file. These files are to be named by the user at runtime.

  Explain initialization parameters of the java servlet

Explain initialization parameters of the java servlet and write advanteges and disadvanteges of the java servlet

  Create a stock class to manage the stock activity

Create a GUI that uses JList andJTabbedPanes - Process multiple objects in an ArrayList and Code event handlers for multiple events

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