Task 1:You are to write two source files as described below:· The first file named stockApp.py, should contain the following two classes:· The first is a class called Stock which defines a simple object type representing a stock being traded in a stock market. · The second class called StockPortfolio defines objects which are containers of Stock objects.· The second file named stockDriver.py defines a Python application, with main method, which creates one StockPortfolio object and allows the various methods of Stock to be called. This class will be an interactive application using the keyboard and the screen to interact with a human operator. It will not do calculations itself but will immediately pass user inputs as arguments to methods of StockPortfolio class.NOTE: The final application will only execute correctly when both files have been defined completely and correctly but don’t wait until you have completely written all three before you start compiling and testing your code. It is recommended that you save both source code files in the same directory on your file system and compile and test each class as you develop it using small separate programs to create ,and test objects of each class.The filesThe files you will require are:Class Stock [saved in stockApp.py]Each stock purchased will have 4 instance variables:· stock name (a string)· amount purchased in lot (an integer, where 1 lot refers to 1000 units)· price purchased (per unit, a float, in RM) · date purchased (a string, where the format is “MM/DD/YYYY”).The methods of class Stock should include:-An initialiser (constructor) method (__init__) which accepts FOUR attributes for a stock – name, amount purchased, price purchased, and date purchased. The method should initialise its object’s attributes with these parametric values. -A reader (getter) method for each of the four attributes. That is, a simple ‘getter’ method for the name, amount purchased, price purchased, and date purchased.-A writer (setter) method for each of the attributes. -A method named value that will return the value of this stock. A stock’s value is calculated by multiplying the purchased price with the amount purchased (in units). For example, a stock purchased with a price of RM3.50 for 2 lots (2000 units) will have a value of RM7000.00-A method __eq__ that takes another Stock as parameter, and returns true if both stocks are equal (same), false otherwise. Two stocks are considered equal if they have the same name.-A method __lt__ that takes another Stock as parameter, and returns true if this stock is having a value less than the parametric stock.-A method __le__ that takes another Stock as parameter, and returns true if this stock is having a value less than or equal to the parametric stock.-A string method (__str__) which return a single string containing the details of a stock. Such a string can be formed by concatenating the values of the four attributes name, amount purchased, price purchased, and date purchased in the format: ( lots @/unit) bought One sample output is as shown below:HELP (2 lots @RM2.35/unit) bought in 10/10/2010It is recommended that once you have written the Stock class, you create a tiny program to test it. The testing program should be used to create one or two Stock objects and call some of the Stock methods. Compile and run the test program to check your work. Class StockPortfolio [written and saved in the same file as StockPortfolio in stockApp.py]This class is to be defined in the same file as class Stock. It declares a class of object with maintains a list of Stock objects. It will contain methods which enable the list to show the appropriate behaviours as required by the menu.The StockPortfolio class should have a client’s name (of type string), and a collection of Stock objects bought by the client, no additional attribute is required:The StockPortfolio class must also contain some methods which allow the collection of stocks to be managed. The methods of class StockPortfolio should include:1. An initialiser (constructor) (__init__) with one argument of type string, which is used to initialise the client’s name. The constructor should also initialise an empty list for storing stocks purchased.2. Getter (reader) methods for accessing the attributes, name and stock list, but only setter (writer) method for name.3. A method named addStock which accepts as an argument an object of class Stock. This method will store a reference to this Stock object into the list.4. A method named noOfStocks which returns the number of Stock objects currently stored in the list.5. A method named allStocks that does not take any parameters, but returns a string containing all the details of all Stock objects, one per line.6. A method named totalValue that does not take any parameters, but returns the total value of all the Stock objects in the portfolio.7. A method named mostExpensiveStock that finds and returns the details of the stock with the highest value. This method does not take any parameters.NOTE: You may assume that there will always be only one stock with the highest value. There will not be a tie between two stocks on values.8. A method named stockSummary that takes a parametric string, representing a stock name. This method will find and return the total value, number of lots, and average value of the purchased stocks with the parametric name. 9. A method named sellStock that takes a positive integer representing the location of the stock to be sold (i.e deleted from the list). If the parametric integer is invalid or out of bounds, then the method should return None.10. A method sortedStocks that takes a parameter of type string. The string represents the criteria to be used in sorting the stock list. The method will return a new list containing all the stocks sorted accordingly to the criteria mentioned in the parametric string in ascending order. The criteria could be lots, price, or value.11. A method saveToFile that accepts a string representing the filename to save, and all Stock objects will be saved to a text file, one per line, with each attribute separated by a comma.12. A method loadFromFile that accepts a string representing the filename where the data is to load from.When you have written the StockPortfolio class – test it by creating a StockPortfolio object and invoking the methods from a small test program. stockDriver.pyThe aim of this file is to provide a user-interface for a modest application which uses a StockPortfolio container class. The user-interface is written as a ‘console’ application using the normal screen and keyboard to interact with a user via a simple text-based menu. The user-interface should create a single StockPortfolio object and provide a menu of choices to the user.The MenuStock portfolio for ———————————1 Buy stock2 Display all stocks’ details3 Display summary information about stock list4 Display stocks with user-specified stock name5 Sell a stock based on a given index6 Display all stocks, sorted according to Stock values7 Load stock information from file8 Save stock information to file0 QuitYour choice?Sample RunPlease note – I’ve truncated display of menu to save space! The menu should display on the screen in full each time it is displayed. User’s input is in blue, and bold.Enter client’s name: Jackson HowardStock portfolio for Jackson Howard———————————-1 Buy stock2 Display all stocks’ details3 Display summary information about stock list4 Display stocks with user-specified stock name5 Sell a stock based on a given index6 Display all stocks, sorted according to stock values7 Load stock information from file8 Save stock information to file0 QuitYour choice? 2No stocks are in the list yet———————————-1 Buy stock…8 Save stock information to file0 QuitYour choice? 1Buying a new stockStock Name: Weyland ConsortiumAmount of Lots: 2Price: 4.5Date: 3/2/2019… bought successfully.Stock portfolio for Jackson Howard———————————-1 Buy stock:8 Save stock information to file0 QuitYour choice? 1Buying a new stockStock Name: Haas-BioroidAmount of Lots: 5Price: 2.75Date: 17/1/2019… bought successfully.Stock portfolio for Jackson Howard———————————-1 Buy stock2 Display all stocks’ details:8 Save stock information to file0 QuitYour choice? 2Details of all stocks:Weyland Consortium (2 lots @RM4.50/unit) bought in 3/2/2019Haas-Bioroid (5 lots @RM2.75/unit) bought in 17/1/2019Stock portfolio for Jackson Howard———————————-1 Buy stock 2 Display all stocks’ details3 Display summary information about stock list:8 Save stock information to file0 QuitYour choice? 3Summary InformationNumber of stocks: 2Total value: RM22750.00Most expensive stock: Haas-Bioroid (5 lots @RM2.75/unit) bought in 17/1/2019 with a total value of RM13750.00Stock portfolio for Jackson Howard———————————-1 Buy stock:4 Display stocks with user-specified stock name:8 Save stock information to file0 QuitYour choice? 4Stock Name: Weyland ConsortiumThe stocks are:Weyland Consortium (2 lots @RM4.50/unit) bought in 3/2/2019Stock portfolio for Jackson Howard———————————-1 Buy stock:6 Display all stocks, sorted according to stock values7 Load stock information from file8 Save stock information to file0 QuitYour choice? 6Sorting stocks- criteria (lots, price, value)? lotsWeyland Consortium (2 lots @RM4.50/unit) bought in 3/2/2019Jinteki Biotech (3 lots @RM6.22/unit) bought in 10/3/2019Haas-Bioroid (5 lots @RM2.75/unit) bought in 17/1/2019Globalsec (6 lots @RM3.24/unit) bought in 8/1/2019Weyland Consortium (7 lots @RM1.01/unit) bought in 10/3/2019Stock portfolio for Jackson Howard———————————-
The post Task 1:You are to write two source files as described below:· The fir appeared first on graduate paper help.
"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"