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 cod.e. It is recommended that you save both source cod.e files in the same directory on your file system and compile and test each class as you develop it using small separate programs to creat and test objects of each class.
The 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:
<name> (<amountInLots> lots @<price>/unit) bought <date>
One sample output is as shown below:
HELP (2 lots @RM2.35/unit) bought in 10/10/2010
It is recommended that once you have written the Stock class, you creat 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:
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.
The 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 creat a single StockPortfolio object and provide a menu of choices to the user.
Stock portfolio for <user’s name>
1 Buy stock
2 Display all stocks’ details
3 Display summary information about stock list
4 Display stocks with user-specified stock name
5 Sell a stock based on a given index
6 Display all stocks, sorted according to Stock values
7 Load stock information from file
8 Save stock information to file
Why Work with Us
Top Quality and Well-Researched Papers
We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.
Professional and Experienced Academic Writers
We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.
Free Unlimited Revisions
If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.
Prompt Delivery and 100% Money-Back-Guarantee
All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.
Original & Confidential
We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.
24/7 Customer Support
Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.
Try it now!
How it works?
Follow these simple steps to get your paper done
Place your order
Fill in the order form and provide all details of your assignment.
Proceed with the payment
Choose the payment system that suits you most.
Receive the final file
Once your paper is ready, we will email it to you.
No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.
No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.
Admission Essays & Business Writing Help
An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.
Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.
If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.