Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java program with comments using the following instructions: Design a class called Stock to store information about a stock transaction : company number

Write a java program with comments using the following instructions:

Design a class called Stock to store information about a stock transaction :

company

number of shares

purchase price

current price.

Your class must include the following member functions:

Default constructor (to initialize all data in class)

Parameterized constructor (to initialize company, shares, purchase price, current price)

Set functions for company, shares, purchase price, current price

getValue function that calculates the value of the stock shares * (current price purchase price)

get functions for company, shares, purchase price, current price

Create an array in main to represent all stocks in my portfolio. Give a maximum size of 10. You will need to keep a counter of how many stocks have been entered.

Create a menu and to process transactions as follows: Your loop that prompts for the users choice must be in main. You should try to write a static function (in the class with main) to process each option (instead of all code in main).

1 Add stock Prompt for data and add to the array. (You only add one at a time).

2 Display profit/loss Print each stock along with its value, and the total value of the portfolio

3 - Quit

SAMPLE OUTPUT:

Portfolio Calculator

1 - Add stock

2 - Show portfolio

3 - Quit

Enter your choice: 1

Enter company: Intel

Number of shares: 100

Purchase price: 29.50

Current price: 36.50

Portfolio Calculator

1 - Add stock

2 - Show portfolio

3 - Quit

Enter your choice: 1

Enter company: Apple

Number of shares: 50

Purchase price: 89.50

Current price: 116.25

Portfolio Calculator

1 - Add stock

2 - Show portfolio

3 - Quit

Enter your choice: 2

Portfolio Report

Company Value

Intel 700.00

Apple 1337.50

Total $ 2037.50

Portfolio Calculator

1 - Add stock

2 - Show portfolio

3 - Quit Enter your choice: 1

Enter company: Cisco

Number of shares: 50

Purchase price: 35.50

Current price: 26.75

Portfolio Calculator

1 - Add stock

2 - Show portfolio

3 - Quit

Enter your choice: 2

Portfolio Report

Company Value

Intel 700.00

Apple 1337.50

Cisco -437.50

Total $ 1600.00

Portfolio Calculator

1 - Add stock

2 - Show portfolio

3 - Quit

Enter your choice: 3

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

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

Students also viewed these Databases questions

Question

Describe positive and neutral messages.

Answered: 1 week ago

Question

4. Who would lead the group?

Answered: 1 week ago

Question

Where those not participating, encouraged to participate?

Answered: 1 week ago