Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm creating a stock selling program in python. Writing a class called 'StockHold' and that will be the customer's stock holding. 'StockHold' will store a

I'm creating a stock selling program in python.

Writing a class called 'StockHold' and that will be the customer's stock holding. 'StockHold' will store a symbol (ABC) for the stock, the number of shares the customer bought, and the price the customer paid per share using an instance variable ('__init__').

Stockhold class should have accessor method for the # of stock symbol (getSymbol), # of shares ('getNumOfShares')

Accessor method for total cost ('getTotalCost') of shares being held. Example, 20 shares of stock at $1 a share, then while they're holding the shares, this method would return $20 (20 x$1). IF they sold 10 shares and now have 10 left, it should return $10 (10x$1).

Method named 'estimateProfit' that has 2 paremeters. First, number of share that can be sold and second, a current price for the shares if they were sold right now. The 'estimateProfit' method should show how much profit the customer would earn if they sold that # of shares at the current price. This can be a negative value.

A mutator method names 'sellShares' with 1 parameter, a number of shares to sell, that change the value of shares being held by subtracting the # of shares to be sold from the # of shares held. A ValueError should be thrown if the customer tries to sell more shares than they own.

The main function in the below code will help test.

Create an instance of your `StockHolding` class

Output the result of calling the accessor methods to show the `StockHolding` object is properly initialized

Call the `estimateProfit` method and, using a conditional statement, output a message only if the returned estimated profit is the value you expect

Call the `sellShares` method and, using a conditional statement with the shares accessor, output a message only if the number of shares after selling is the value you expect

Call the `sellShares` method attempting to sell more shares than you have to show the ValueError is raised

class StockHolding: def __init__( self ): print("THIS IS JUST A PLACEHOLDER IN THE CONSTRUCTOR, REMOVE THIS MESSAGE!")

def main(): testStockHolding = StockHolding() print( "DO NOT FORGET THE REQUIRED TESTING IN THIS main FUNCTION, ALSO REMOVE THIS MESSAGE!")

main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions