python
In object-oriented programming (OOP), private attribute means that we don't want this attribute to be accessed outside the class object. Explore how to define a private method/ attribute and finish the following questions. Design a class named Stock to represent a company's stock that contains: Initiate method: . . A private string data field named symbol that stores stock's symbol A private string data field named name that stores stock's name A private float data field named previousClosingPrice that stores previous day's stock price A private float data field named currentPrice that stores current stock price . Instance method: . . . A get method for returning the stock name A get method for returning the stock symbol Get and set methods for getting/setting stock's previous price Get and set methods for getting/setting stock's current price A method named getChangePercent() that returns the percentage changed from previousClosingPrice to currentPrice After you finish the class construction, write a test program that creates a Stock object with the stock symbol ‘INTC', the name 'Intel Corporation', the previous closing price of 20.5, and . the current price of 20.35. Display the price change percentage. Based on the class example you write, please discuss the benefits of OOP.
In object-oriented programming (OOP), private attribute means that we don't want this attribute to be accessed outside t
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
In object-oriented programming (OOP), private attribute means that we don't want this attribute to be accessed outside t
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!