Assignment For this project, you get to design and write a stock class to keep track of the profit of stock purchases. You also get to design and write stockDriver class that requests input from the user and interacts with the stock class. Your stock class should store the following information: • Total number of shares purchased • Total cost basis (defined above) Provide the following methods in your stock class: • No-argument constructor that initializes both the total number of shares purchased and the total cost basis • addstockPurchase () that takes the number of shares purchased (as an int) and the price per share (as a double). This method should add the newly purchased shares to the total number of shares purchased and update the cost basis (with the number of shared purchased multiplied by the price per share). • getNumberofShares () returns the total number of shares purchased as an int • getCostBasis () returns the total cost basis as a double, rounded to 2 decimals because it is money • calculateProfit () that takes the price per share (at the time of the sale) (as a double) and returns the profit of selling all of the shares (as a double, rounded to 2 decimals because it is money) Your StockDriver class should create a stock object to keep track of the user's input. First, it requests the number of stock purchases from the user. For each purchase, it prompts the user for the number of shares purchased (a positive number greater than 0)., then the price per share (a positive number greater than 0.0). While either of these inputs are negative or equal to o (or 0.0), it prompts the user again before proceeding with the next input. Note, if the user provided an invalid number of shares purchased, the program repeatedly requests valid input before requesting the price per share. After all purchases are inputted, the user is prompted for the the price per share at the time of sale (a positive number greater than 0.0). Again, if an invalid number is entered, the program should repeatedly request valid input. Note, do not keep track of the cost basis in your stockDriver class. Instead, make the appropriate method calls using the stock object. Each of the methods in your stock class will be tested using unit tests. Additionally, the output of your entire program will be tested with various inputs. . Examples (user input in bold text) Example 1 (with invalid input) Welcome to the Stocks Profit Calculator! Please enter the number of stock puchases: 3 Please enter the number of shares purchased: -99 Please enter the number of shares purchased: 0 Please enter the number of shares purchased: 100 Please enter the price per share: 0.0 Please enter the price per share: -98.76 Please enter the price per share: 5.5 Please enter the number of shares purchased: -100 Please enter the number of shares purchased: 100 Please enter the price per share: 5.15 Please enter the number of shares purchased: 100 Please enter the price per share: 6.16 The cost basis is $1681.0. To calculate the profit, please enter the price per share of a sale: -6.25 To calculate the profit, please enter the price per share of a sale: 6.25 The profit from selling 300 shares at 6.25 each is $194.e. Notice that multiple invalid values are entered and that the program keeps asking for a valid values until it gets a valid one. Also notice that the cost basis and profit are each rounded. If you're trying to debug this example (and I hope that you would), you could temporarily display the cost basis after each valid price per purchased share is entered. That should give you the following values: The current cost basis is $550.0. The current cost basis is $1065.0. The current cost basis is $1681.e.
Assignment For this project, you get to design and write a stock class to keep track of the profit of stock purchases. You also get to design and write stockDriver class that requests input from the user and interacts with the stock class. Your stock class should store the following information: • Total number of shares purchased • Total cost basis (defined above) Provide the following methods in your stock class: • No-argument constructor that initializes both the total number of shares purchased and the total cost basis • addstockPurchase () that takes the number of shares purchased (as an int) and the price per share (as a double). This method should add the newly purchased shares to the total number of shares purchased and update the cost basis (with the number of shared purchased multiplied by the price per share). • getNumberofShares () returns the total number of shares purchased as an int • getCostBasis () returns the total cost basis as a double, rounded to 2 decimals because it is money • calculateProfit () that takes the price per share (at the time of the sale) (as a double) and returns the profit of selling all of the shares (as a double, rounded to 2 decimals because it is money) Your StockDriver class should create a stock object to keep track of the user's input. First, it requests the number of stock purchases from the user. For each purchase, it prompts the user for the number of shares purchased (a positive number greater than 0)., then the price per share (a positive number greater than 0.0). While either of these inputs are negative or equal to o (or 0.0), it prompts the user again before proceeding with the next input. Note, if the user provided an invalid number of shares purchased, the program repeatedly requests valid input before requesting the price per share. After all purchases are inputted, the user is prompted for the the price per share at the time of sale (a positive number greater than 0.0). Again, if an invalid number is entered, the program should repeatedly request valid input. Note, do not keep track of the cost basis in your stockDriver class. Instead, make the appropriate method calls using the stock object. Each of the methods in your stock class will be tested using unit tests. Additionally, the output of your entire program will be tested with various inputs. . Examples (user input in bold text) Example 1 (with invalid input) Welcome to the Stocks Profit Calculator! Please enter the number of stock puchases: 3 Please enter the number of shares purchased: -99 Please enter the number of shares purchased: 0 Please enter the number of shares purchased: 100 Please enter the price per share: 0.0 Please enter the price per share: -98.76 Please enter the price per share: 5.5 Please enter the number of shares purchased: -100 Please enter the number of shares purchased: 100 Please enter the price per share: 5.15 Please enter the number of shares purchased: 100 Please enter the price per share: 6.16 The cost basis is $1681.0. To calculate the profit, please enter the price per share of a sale: -6.25 To calculate the profit, please enter the price per share of a sale: 6.25 The profit from selling 300 shares at 6.25 each is $194.e. Notice that multiple invalid values are entered and that the program keeps asking for a valid values until it gets a valid one. Also notice that the cost basis and profit are each rounded. If you're trying to debug this example (and I hope that you would), you could temporarily display the cost basis after each valid price per purchased share is entered. That should give you the following values: The current cost basis is $550.0. The current cost basis is $1065.0. The current cost basis is $1681.e.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Concept explainers
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Question
100%
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education