Question: 3 . 7 [ Assignment 3 ] Stock and Portfolio You have been provided with 2 classes Stock and Portfolio. The Stock class describes the

3.7[Assignment 3] Stock and Portfolio
You have been provided with 2 classes Stock and Portfolio.
The Stock class describes the template for stocks. Stocks have 3 fields/properties String stockName, int numberOfShares, double priceOfShare The constructor of Stock takes 3 parameters corresponding to the fields/properties of the Stock class. You have been provided with an accessor/mutator for all three fields (stockName, numberOfShares, and priceOfShare).*Note: the Stock.java class is read-only. 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 fields/properties and has a main method. Within Portfolio, there are currently 4 Stock objects corresponding to 4 companies. Observe the code and how it calls the Stock class's constructor.
Task 0: 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 1: Portfolio.java
Work within the main method of the Portfolio class after the existing code and accomplish the following:
Declare and initialize 2 new Stock objects for Facebook and LinkedIn respectively with the following parameters:
stockName: Facebook numberOfShares:300, priceOfShare: 75
stockName: LinkedIn numberOfShares:500, priceOfShare: 100
//(Note the I is capitalized in LinkedIn).
Print out information about the complete portfolio, i.e. 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 : 10000
Stock Price : 500.0
Stock Name : Apple
Stock Quantity : 1000
Stock Price : 50.0
Stock Name : General Electric
Stock Quantity : 1001
Stock Price : 51.0
Stock Name : General Motors
Stock Quantity : 2001
Stock Price : 25.0
Stock Name : Facebook
Stock Quantity : 300
Stock Price : 75.0
Stock Name : LinkedIn
Stock Quantity : 500
Stock Price : 100.0
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 "hard-coded" to print. Any points that were earned from "hard-coding" 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 (end-of-class) will be recorded for an in-class activity grade.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!