Question
Task back to top Flock Stock Professionals have asked you to extend the program from assignment 1 with these additional features. Program should prompt for
Task
back to top
Flock Stock Professionals have asked you to extend the program from assignment 1 with these additional features.
- Program should prompt for three (3) stock holdings, not just one.
- It should get date inputs in YYYY-MM-DD format. (Assume that user will not make any mistake in typing the dates.)
- Instead of asking for clients income tax rate, the program will ask for their annual gross income (in the financial year shares were sold) and then work out the tax rate automatically according to table below.
- After entering stock data for all holdings, the program should display a bar chart of raw capital gains from all holdings. Use Python turtle graphics to draw the chart.
Annual gross income | Tax rate |
0 $18,200 | 0 |
$18,201 $37,000 | 19% |
$37,001 $90,000 | 32.5% |
$90,001 $180,000 | 37% |
$180,001 and over | 45% |
To work with dates, you are provided with a monthcalc python module. Download it here. It contains a single function with the following definition:
def twelve_month_apart (date1, date2): ....
This function takes in two date parameters (both strings, in YYYY-MM-DD format) and returns True if date2 is later than date1 by twelve months or more. Otherwise it returns False. You do not need to understand the code in this module but you will import it and use the above function in order to check for CGT discount eligibility.
To draw the bar chart using turtle graphics, you are required to create two functions
- draw_axes(left_bottom_x, left_bottom_y, width, height, y_max) This will draw the axes as shown in figure below. The parameters left_bottom_x and left_bottom_y indicate the coordinates of origin point. width and height define the size of bar chart (in pixels). y_max is the maximum value this chart can display (1000 in figure below). As you can see in figure, this function should also draw five horizontal dim lines to indicate five steps up to y_max.
- draw_bar(middle_x, bottom_y, width, height) Calling this function once will draw a single rectangular bar such with (middle_x, bottom_y) as the base point. width and height define the size of a single bar (again in pixels).
Use the above two functions to plot the raw capital gains from each of the three stock holdings. Do not show a bar for capital losses.
Review the sample run below to clearly understand all requirements of your program.
=== Enter data for stock holding 1 === Purchase date (YYYY-MM-DD) : 2019-01-04 Sale date (YYYY-MM-DD) : 2019-10-11 Number of shares : 165 Purchase price per unit : 12.36 Sale price per unit : 19.81 Client's annual gross income: 70365 Total purchase value = $2,039.40 Total sale value = $3,268.65 Capital gains = $1,229.25 This stock was held for less than 12 months. Client is *not* eligible for a discount on capital gains tax. Taxable capital gains = $1,229.25 Income tax rate = 32.5% Tax due = $399.51 === Enter data for stock holding 2 === Purchase date (YYYY-MM-DD) : 2016-10-05 Sale date (YYYY-MM-DD) : 2020-12-25 Number of shares : 78 Purchase price per unit : 52.30 Sale price per unit : 49.55 Client's annual gross income: 95500 Total purchase value = $4,079.40 Total sale value = $3,864.90 Capital gains = $-214.50 Client made a capital loss. No taxes are applicable. === Enter data for stock holding 3 === Purchase date (YYYY-MM-DD) : 2018-01-08 Sale date (YYYY-MM-DD) : 2021-02-28 Number of shares : 480 Purchase price per unit : 23.11 Sale price per unit : 39.72 Client's annual gross income: 35120 Total purchase value = $11,092.80 Total sale value = $19,065.60 Capital gains = $7,972.80 The stock was held for 12 months or more. Client is *eligible* for a discount on capital gains tax. Taxable capital gains = $3,986.40 Income tax rate = 19% Tax due = $757.42 === Bar chart opens in new window === Thanks for using this app. |
Constraint: You can only import these Python modules: turtle, math and monthcalc
You should follow good programming practices, for example using named constants, creating several functions (top down design) and minimizing the use of global variables.
---
Your assignment should consist of following tasks.
Task 1
Draw a flowchart of your main() function, including flowcharts for all other functions that are called by main() except draw_axes and draw_bar (you do not need to flowchart these two).
You can draw the flowcharts with a pen/pencil on a piece of paper and scan it for submission, as long as the handwriting is clear and legible. However, it is strongly recommended to draw flowcharts using a drawing software.
Task 2
Select four sets of test data that will demonstrate the 'normal' operation of your program; that is, test data that will demonstrate what happens when a valid input is entered. Select three sets of test data that will demonstrate the 'abnormal' operation of your program. Please note that for this application, user input includes mouse clicks as well as keyboard button presses.
Set out test results in a tabular form as follows. It is important that the output listings (i.e. screenshots) are not edited in any way.
Test Data Table | ||||
---|---|---|---|---|
Test data type | Test data | The reason it was selected | The output expected due to the use of the test data | The screenshot of actual output when the test data is used |
Normal | ||||
Normal | ||||
Abnormal | ||||
Abnormal |
Task 3
Implement your program in Python. Comment on your code as necessary to explain it clearly. Run your program using the test data you have selected and complete the final column of test data table above.
Your submission will consist of:
- Your algorithm through flowchart/s
- The table recording your chosen test data and results (it should be a Word file)
- Source code for your Python implementation
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started