Menu

(Solved) : M Creating Stock Selling Program Python Writing Class Called Stockhold Customer S Stock Ho Q30652363 . . .

I’m creating a stock selling program in python.

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

Stockhold class should have accessor method for the # of stocksymbol (getSymbol), # of shares (‘getNumOfShares’)

Accessor method for total cost (‘getTotalCost’) of shares beingheld. Example, 20 shares of stock at $1 a share, then while they’reholding the shares, this method would return $20 (20 x$1). IF theysold 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 forthe shares if they were sold right now. The ‘estimateProfit’ methodshould show how much profit the customer would earn if they soldthat # of shares at the current price. This can be a negativevalue.

A mutator method names ‘sellShares’ with 1 parameter, a numberof shares to sell, that change the value of shares being held bysubtracting the # of shares to be sold from the # of shares held. AValueError should be thrown if the customer tries to sell moreshares 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 conditionalstatement, output a message only if the returned estimated profitis the value you expect

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

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

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

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

main()

Expert Answer


Answer to M Creating Stock Selling Program Python Writing Class Called Stockhold Customer S Stock Ho Q30652363 . . .

OR