WARNING: After submission, two types of tests will be performed. The ‘General’ tab provides feedback on instance variable and method definitions. The ‘Evaluation after exam’ tab shows the tests used for evaluation after submission.

Given:

The Python project Stocks1 is used to keep track of your stock portfolio. Each stock has a Market code, a Ticker (i.e., stock name abbreviation), a price, and a quantity. The stocks in your portfolio are read in from a text file. Figure 1 shows the lines of this file:

NASDAQ;NFLX;447.77;15
NASDAQ;AMZN;2640.98;3
NASDAQ;AAPL;351.59;10
NASDAQ;TSLA;991.79;5
NASDAQ;MSFT;194.24;6
NYSE;DIS;117.65;3
NYSE;BAC;25.00;100
NYSE;JPM;99.45;15
NYSE;WMT;119.03;23
NYSE;T;30.25;45

The project contains two classes. The FileReader class reads a text file with a portfolio in the format described above when instantiated (by default, the file is “portfolio.txt”). The class interface provides the following methods:

As shown in the figure below, FileReader uses the AandeelData class. Each object of this class represents the data of one stock. The class has the following methods:

Required:

We will add simple management tasks for a stock portfolio to the AandelenPortefeuille class using 10 methods.

Question 1 (2 points)

Create a class AandelenPortefeuille.

Question 2 (2 points)

Add a parameterless constructor to the AandelenPortefeuille class. This constructor will first initialize a new FileReader object reader and a dictionary portefeuille_map as instance variables. Then, it will use the reader object to add the AandeelData entries one by one to the portefeuille_map dictionary. The key will be created using the static create_key method of the AandeelData class.

Question 3 (2 points)

Add a public method aandeel_aanwezig with parameters a string markt and a string ticker. If the stock is present in the instance variable portefeuille_map, the method should return True, otherwise, it should return False. You can determine if a stock is present by examining the key of the portefeuille_map instance variable.

Question 4 (2 points)

Add a public method toevoegen_aandeel with as parameter an AandeelData object. This object should only be added if the stock is not already present in the portfolio. If the stock could be added, the method should return True, otherwise, it should return False.

Question 5 (2 points)

Add a public method aanpassen_aandeel with parameters a string market, a string ticker, a float prijs, and int aantal. The method should adjust the price and quantity of a stock if it is present in the portefeuilleMap collection. If the stock is not present in the collection, nothing should be modified.

Question 6 (2 points)

Add a public method waarde_aandeel with parameters string markt and a string ticker. The method should return the value of a stock as a float based on the price and quantity. If the stock is not present in the collection, the method should return 0.

Question 7 (2 points)

Add a public method totale_waarde. The method should return the total value of the portfolio as a float.

Question 8 (2 points)

Add a public method get_aandelen_markt with a market code as a string parameter. This method should return a list of AandeelData objects listed on the market that matches the given parameter. If the market does not exist, an empty list should be returned.

Question 9 (2 points)

Add a public method get_kleinste_aandeel. This method should return the key (market-stock) of the stock with the lowest value (price * quantity).

Question 10 (2 points)

Add a public method rapport. This method should print a report in the console in the following format:

Portfolio
----------------
NYSE T  30.25 45
NASDAQ AMZN  2640.98 3
NYSE DIS  117.65 3
NYSE WMT  119.03 23
NASDAQ NFLX  447.77 15
NASDAQ MSFT  194.24 6
NYSE JPM  99.45 15
NASDAQ TSLA  991.79 5
NYSE BAC  25.0 100
NASDAQ AAPL  351.59 10
TOTAL VALUE: 32723.42