Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3 . 7 [ Assignment 3 ] Stock and Portfolio You have been provided with 2 classes Stock and Portfolio. The Stock class describes the
Assignment Stock and Portfolio
You have been provided with classes Stock and Portfolio.
The Stock class describes the template for stocks. Stocks have fieldsproperties String stockName, int numberOfShares, double priceOfShare The constructor of Stock takes parameters corresponding to the fieldsproperties of the Stock class. You have been provided with an accessormutator for all three fields stockName numberOfShares, and priceOfShareNote: the Stock.java class is readonly. You will need to copy this file into your eclipse project for Portfolio to interact with it but the Stock file itself requires no modification from you.
The Portfolio class does not have any fieldsproperties and has a main method. Within Portfolio, there are currently Stock objects corresponding to companies. Observe the code and how it calls the Stock class's constructor.
Task : Stock.java
Read through the Stock class to see what it does and what public methods are available to you.
Recommended: comment above each method with a summary explanation of its function.
Task : Portfolio.java
Work within the main method of the Portfolio class after the existing code and accomplish the following:
Declare and initialize new Stock objects for Facebook and LinkedIn respectively with the following parameters:
stockName: Facebook numberOfShares: priceOfShare:
stockName: LinkedIn numberOfShares: priceOfShare:
Note the I is capitalized in LinkedIn
Print out information about the complete portfolio, ie the information about all the stocks owned in the following order: Amazon, Apple, Facebook, GE GM and LinkedIn hint: they each have a method that can print out their information
This should be accomplished by calling the existing method that prints their information in the below format. Inspect Stock.java to find out which methods you can use!
Stock Name : Amazon
Stock Quantity :
Stock Price :
Stock Name : Apple
Stock Quantity :
Stock Price :
Stock Name : General Electric
Stock Quantity :
Stock Price :
Stock Name : General Motors
Stock Quantity :
Stock Price :
Stock Name : Facebook
Stock Quantity :
Stock Price :
Stock Name : LinkedIn
Stock Quantity :
Stock Price :
Calculate and print the total dollar value of stocks in the entire portfolio.
Each stock has a value accessible by calling the calcualteStockValue method found in the Stock class. Inspect this method to see how it works.
You should sum add up each stock object's value returned by the calcualteStockValue method and print the total sum. Ex: totalSum amazon's total stock value apple's total stock value
Note: All code will be checked manually that the Stock class's methods were used and the value was not "hardcoded" to print. Any points that were earned from "hardcoding" in the final stock value will be deducted.
Submission
You should test your code thoroughly and check that your calculations are correct before submitting. Submissions are unlimited. Your highest score before the deadline endofclass will be recorded for an inclass activity grade.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started