Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SOLVE IN PYTHON: Exercise #2: Design and implement class Stock to represent a companys stock. The class defines the following attributes (variables) and methods: A

SOLVE IN PYTHON: Exercise #2: Design and implement class Stock to represent a companys stock. The class defines the following attributes (variables) and methods:

A class variable of type String named Symbol for the stocks symbol.

A class variable of type String named Name for the stocks name.

A class variable of type double named previousClosingPrice to store the last closing price.

A class variable of type double named currentPrice to store the current price.

A constructor method to create a stock with user-specified name and symbol.

Method getName() that returns the stocks name.

Method getSymbol() that returns the stocks symbol.

Method setClosingPrice() that sets the previous closing price.

Method setCurrentPrice() that sets the current price.

Method getChangePercent() that returns the percentage changed from

previousClosingPrice to currentPrice.

Use the formula: (currentPrice - previousClosingPrice)/ currentPrice * 100

Method named toString() (Java & C#) or ___str___() (Python) to printout a meaningful description of a stock object when passing the object name to the print statement.

e.g.: The statement PRINT yahooStock would print the string:

Yahoo stocks closing price is $234.54.

Now design and implement a test program to create two stock objects: one for Google with symbol GOG and the second is for Microsoft with symbol MSF. Set their closing and current prices according to the information below. Next, test the class methods on each object to print in the information in a similar manner to the one shown below:

Sample run:

Google stock:

Symbol: GOG

Closing price: 134.67

Current price: 131.98

Change percent: - 2%

Google stock closing price is $131.98

Microsoft stock:

Symbol: MSF

Closing price: 156.52

Current price: 161.22

Change percent: 3%

Microsoft stock closing price is $161.22

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

Students also viewed these Databases questions

Question

explain what is meant by experiential learning

Answered: 1 week ago

Question

identify the main ways in which you learn

Answered: 1 week ago