Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Write a program that asks the user to enter the name, opening price, closing price, and number of shares owned for a stock. Have

Java

Write a program that asks the user to enter the name, opening price, closing price, and number of shares owned for a stock. Have the program compute the current value of the stock (hint: closing value time number of shares owned) and the amount gained or lost. Display the stock name, opening price, closing price, number of shares, opening value, closing value, and the gain/loss. Additionally, you will ask the user for a file to write the data to.

Create an if statement that tells the user whether the stock has gained or lost value based on the gain/loss (see example below).

Data validation: Ensure the user enters values greater than zero for the opening price, closing price and number of shares. Give an error statement if invalid. Use a priming read to do this (if necessary).

Loops: encapsulate all of the above in a loop that asks if the user wants to enter another stock and continues to run as long as the user answers yes (remember to use the proper string comparison technique).

Use String.format or DecimalFormat to format the output as shown in the following example to both the screen/dialog box and the file the user specified:

Stock: MSFT Opening Price: $30.00 Closing Price: $35.00 Number of Shares: 1000 Opening Value: $30,000.00 Closing Value: $35,000.00 Gain/Loss: Your portfolio gained $5,000.00 in value

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions