Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Write a program that calculates stock value and dividend yield: Input the following five variables use an input prompt and align the input: stock

Java

Write a program that calculates stock value and dividend yield:

Input the following five variables use an input prompt and align the input:

stock name; stock ticker; stock price; shares owned; annual dividend

Create a method that calculates stock value (price multiplied by # of shares)

Round to two decimal places

Call this method to get the stock value

Create a method that calculates the dividend yield (annual dividend divided by stock price)

Dividend yield is stated as a percentage: round to two decimal places

Call this method to get the dividend yield

Create a method that prints formatted output: a message, a value and %, if needed

Call this method to display the stock value on the monitor

Call this method to display the dividend yield on the monitor

At the beginning of the program, input your name from the keyboard.

At the end of the program, display a completed message and your name on the monitor.

TEST DATA and EXPECTED RESULTS

Run the program with data for:

Stock name = Exelon

Stock ticker = EXC

Stock price = 34.90

Shares owned = 40.15

Annual dividend = 1.27

Expected results: (calculate what you expect the results to be)

Stock value =

Dividend yield =

You have $1000. Find a stock and purchase shares:

Go to http://finance.yahoo.com/ and browse for stocks (type something in the get quotes box)

Find a stock that has a dividend

Figure out how many shares you can purchase for $1000

Run the program with your stock data: (fill this in)

Stock name =

Stock ticker =

Stock price =

Shares owned =

Annual dividend =

Expected results: (calculate what you expect the results to be)

Stock value =

Dividend yield =

SAMPLE RUN OF PROGRAM

Welcome to the Stock Program.

Please enter the following information:

Your name > Name

Stock name > Exelon

Stock ticker > EXC

Stock price > 30.03

Shares owned > 33.03

Annual dividend > 2.10

Stock value = 991.89

Dividend yield = 6.99%

Program completed. Thank you, Name

This is the template to use

import java.util.*;

public class Lab01

{//start of class

public static void main(String [] args)

{// start of main method

Scanner keyBoard = new Scanner(System.in);

// assigns "keyBoard" to keyboard

//System.out displays on the monitor

//Variables and defined constants go here - add comments for each variable

//Data Dictionary

double stockPrice; //price of one share of stock

//instructions start here

//input: input prompts and input of data go here

//process: calculations, process or calls to methods go here

//example:

//To round stockPrice to the nearest thousandth (three decimal places)

//stockPrice = Math.round (stockPrice * 1000.0) / 1000.0;

//output: monitor display goes here

}//end of main

//methods go here

}//end of class

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

4. What sales experience have you had?

Answered: 1 week ago

Question

15-5 How will MIS help my career?

Answered: 1 week ago