In this assignment, you will implement a simplified stock market system. You will start by building classes to represent a stock, an owned stock (result of a transaction) and your own hierarchy of...

In this assignment, you will implement a simplified stock market system. You will start by building classes to represent a stock, an owned stock (result of a transaction) and your own hierarchy of exceptions in phase 1. In phase 2, you will build a hierarchy of investing account classes (see the representation below). Finally, in phase 3, you will build a market that has a list of stocks and a list of accounts that can trade those stocks. Moreover, you will build methods to read and execute commands / transactions from a text file.


ASSIGNMENT 3: Object hierarchies, inheritance and polymorphism COMP 1020 Winter 2021 Page 1 of 9 DUE DATE: MARCH 31ST, 2021 AT 4:59PM Instructions:  You must complete the “Blanket Honesty Declaration” checklist on the course website before you can submit any assignment.  Only submit the java files. Do not submit any other files, unless otherwise instructed.  To submit the assignment, upload the specified files to the Assignment 3 folder on the course website.  Assignments must follow the programming standards document published on UMLearn.  After the due date and time, assignments may be submitted but will be subject to a late penalty. Please see the ROASS document published on UMLearn for the course policy for late submissions.  If you make multiple submissions, only the most recent version will be marked.  These assignments are your chance to learn the material for the exams. Code your assignments independently. We use software to compare all submitted assignments to each other, and pursue academic dishonesty vigorously.  Your Java programs must compile and run upon download, without requiring any modifications.  Automated tests will be used to grade the output of your assignment. If you do not follow precisely the guidelines described below, these automated tests can fail and you will lose marks. In particular, make sure that your methods are spelled exactly as described below. Also, make sure that your code produces exactly the example outputs (including correct spacing) shown in these guidelines. Assignment overview In this assignment, you will implement a simplified stock market system. You will start by building classes to represent a stock, an owned stock (result of a transaction) and your own hierarchy of exceptions in phase 1. In phase 2, you will build a hierarchy of investing account classes (see the representation below). Finally, in phase 3, you will build a market that has a list of stocks and a list of accounts that can trade those stocks. Moreover, you will build methods to read and execute commands / transactions from a text file. The hierarchies of classes that you will build are represented here (except the Exception class in the white box, because it already exists): InvalidTransaction Exception InsufficientFunds Exception Exception InvestingAccount InvestingApp PremiumAccount ASSIGNMENT 3: Object hierarchies, inheritance and polymorphism COMP 1020 Winter 2021 Page 2 of 9 As usual, focus on keeping all of your methods short and simple. In a properly-written object-oriented program, the work is distributed among many small methods, which call each other. Some methods in Phase 3 will require more lines of code, and that’s ok. Unless specified otherwise, all instance variables must be private, and all methods should be public. You should not use the protected access modifier in this assignment: each class should be responsible for managing their own data (instance variables). Testing Your Code We have provided sample test files for each phase to help you verify that your code is working to the assignment specifications. These files are only starting points for testing your code. Part of developing your skills as a programmer is to think through additional important test cases and to write your own code to test these cases. The test files should give you a sense what this additional code could consist of. Phase 1: Stock, OwnedStock and the hierarchy of exceptions First, implement two simple classes: a Stock class and an OwnedStock class. The Stock class should have:  Four instance variables: the name of the stock (a String), the symbol of the stock (a String), the current price (a double) and the change in price (a double). The change in price instance variable will store the variation every time the current price changes (e.g. if the current price goes from 10 to 8, the change in price will be -2).  A constructor that has three parameters (String, String, double), which are used to initialize the first three instance variables described above (in the same order). A newly instantiated Stock has an initial change in price of 0.  A standard toString() method, which returns a String containing the Stock’s name, symbol (in between parentheses), current price and change in price (in between parentheses). Format this string as shown in the output below. Use the String.format method to insert the double values with only 2 digits after the decimal point.  Two accessor methods: getSymbol() which returns the Stock’s symbol, and getCurrentPrice() which returns the current price of the Stock.  A void method changeCurrentPrice(double) which sets the Stock’s current price to the double value received as a parameter. This method must also update the change in price instance variable. The OwnedStock class represents a previous transaction that has been made. It stores all the information about that transaction (a number of shares of one particular stock traded at a specific price). It should have:  Three instance variables: the quantity of shares traded (an int), the Stock that was traded (a Stock) and the transaction price per share (a double).  A constructor with three parameters (int, Stock, double), which are used to initialize the three instance variables described above (in the same order).  Two accessor methods getQuantity() and getStock() that return the values of the corresponding instance variables.  A double getValue() method, which returns the total value of the transaction (for all traded shares).  A double getProfit() method, which calculates how much profit (or potentially loss) has been made, considering the current value of the shares owned.  A toString() method which returns a String containing the quantity of shares, the Stock symbol, the transaction price (per share) and the total value paid (given by getValue()) in between parentheses. See the example output below for the exact formatting.  A double addShares(int, double) method, which adds to the number of owned shares the int value received as a parameter, at the price given by the double parameter. This method must update the transaction price instance variable to reflect the new average price of both transactions. The method must return the total value of the most recent transaction (the purchase that has just been made). ASSIGNMENT 3: Object hierarchies, inheritance and polymorphism COMP 1020 Winter 2021 Page 3 of 9  A double sellShares(int, double) method, which reduces the number of owned shares by the amount (int value) received as a parameter. The double value represents the price (per share) of the transaction. This method must return the total value of that sale. Second, implement these two simple exception classes: an InvalidTransactionException class and an InsufficientFundsException class. The InvalidTransactionException class should:  Be a subclass of the Exception class (of Java).  Have a constructor that takes a message (String) parameter. It should only call the super constructor with that message. The InsufficientFundsException class should:  Be a subclass of the InvalidTransactionException class.  Have a constructor that takes a message (String) parameter. It should only call the super constructor with that message. These exception classes will be used in the next phases. You can test your classes using the supplied test program TestPhase1.java. You should get the output below. GameStonk (GMS): 400.00 (change: 0.00) GameStonk (GMS): 350.00 (change: -50.00) GameStonk (GMS): 360.00 (change: 10.00) 10 of GMS at 360.00 (total value paid = $3600.00) Profit = $0.00 GameStonk (GMS): 350.00 (change: -10.00) Profit = $-100.00 After buying 10 more shares: The cost of the transaction: 3500.00 20 of GMS at 355.00 (total value paid = $7100.00) Profit = $-100.00 GameStonk (GMS): 400.00 (change: 50.00) 20 of GMS at 355.00 (total value paid = $7100.00) Profit = $900.00 After selling 15 shares: Received this much from the sale: 6000.00 5 of GMS at 355.00 (total value paid = $1775.00) Profit = $225.00 Testing short selling: -100 of GMS at 400.00 (total value paid = $-40000.00) GameStonk (GMS): 100.00 (change: -300.00) Profit = $30000.00 Problem with a transaction! Not enough funds! ASSIGNMENT 3: Object hierarchies, inheritance and polymorphism COMP 1020 Winter 2021 Page 4 of 9 Phase 2: The InvestingAccount hierarchy Next, implement the InvestingAccount, InvestingApp and PremiumAccount classes following the descriptions below. The InvestingAccount class must be an abstract class. It should have:  Five main instance variables: the name of the platform used for investing (a String), the cash balance in the account (a double), the account number (a long), the owner of the account (a String), and an ArrayList of OwnedStocks objects (ArrayList) representing the stocks currently held in the account.  A class variable (a long) that will allow us to set a unique account number to each account. The first InvestingAccount created should have the following account number: 100000000000. This value should be incremented each time an InvestingAccount is created, so that the next InvestingAccount would have this account number: 100000000001 (and so on).  A constructor that accepts the platform name (a String), the initial cash balance (a double), and the owner (a String) and initializes the corresponding instance variables. The constructor should also initialize the account number and initialize the ArrayList to be empty at the beginning.  Two accessor methods: getAccountNumber() which returns the account number, and getCashBalance() which returns the cash balance.  A double getNetWorth() method that returns the current net worth of everything that is held in the InvestingAccount. The net worth takes into account the cash balance, and the current value of the stocks owned (not the value that the stocks had when they were initially purchased  the current
May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here