Question
LAB03:Arrays I NEED THE ANSWER FOR LAB03 IN WHICH YOU NEED USE ARRAY AND LAB03 IS CONTINUE PART OF LAB02 SO THERE IS REFERENCE OF
LAB03:Arrays I NEED THE ANSWER FOR LAB03 IN WHICH YOU NEED USE ARRAY AND LAB03 IS CONTINUE PART OF LAB02 SO THERE IS REFERENCE OF LAB02 TO LOOK AND GET ANSWER FOR LAB03
OBJECTIVE
To demonstrate defining and initializing arrays
To demonstrate processing arrays sequentially
To demonstrate a sequential search through an array using a method
SPECIFICATIONS
Start with the Java program from LAB02 and save it as LAB03.java
Make the following changes:
Create parallel arrays for the stock ticker and the stock name
Parallel arrays are two separate arrays that are positionally linked,
for example: the ticker in row 0 is the ticker for the stock name in row 0
Initialize these using file Lab03ArrayFile.txt, which contains the tickers and the stock names
Lab03ArrayFile.txt (the following list is Lab03ArrayFile.txt)
ATVI Activision Blizzard
AXP American Express
COKE Coca-Cola
CSCO Cisco
CVS Caremark Corp
DIS Walt Disney
EXC Exelon
F Ford Motor
GOOG Google
HD The Home Depot
IBM Inter Business Mach
INTC Intel Corporation
MSFT Microsoft Corp
NIK NIKE, Inc
NVS Novartis
SNE Sony
SPLS Staples
T AT&T
TXN Texas Instrument
WAG Walgreens
WMT Wal-mart
Create a method that will display a list of stock tickers and stock names on the monitor.
Call this method before the main process loop.
Create a method that will do a sequential search through the arrays:
Search through the ticker array to find a match for the input ticker
If no match is found, use Invalid Stock Ticker for the stock name
Use the corresponding stock name as output to the report
Refer to Java06SequentialSearch
NOTE: you must trim extra spaces or tabs off of two variables:
The stock name for the array AND the stock ticker from the stock input file
Input file is Lab03Input.txt (the following table is Lab03Input.txt file)
42.87 23.33 2.10 EXC
12.00 83.33 0.17 ATVI
28.15 35.00 0.80 MSFT
42.98 23.26 0.65 CVS
33.64 29.72 2.20 TXN
55.51 18.01 2.00 NVS
16.00 62.50 0.40 SPLS
19.81 50.47 0.24 CSCO
30.09 33.23 1.76 T
39.29 25.45 0.60 DIS
18.65 53.00 0.29 SNE
50.21 19.21 0.72 AXP
102.69 9.74 1.44 NIKE
Output file to be created: Lab03Report.txt
SAMPLE output report
Stock Value and Yield Report
Stock Ticker & Name Price Shares Value Dividend Yield
xxxx xxxxxxxxxxxxxxxx 99.99 99.999 9999.99 99.99 9.99%
xxxx xxxxxxxxxxxxxxxx 99.99 99.999 9999.99 99.99 9.99%
xxxx xxxxxxxxxxxxxxxx 99.99 99.999 9999.99 99.99 9.99%
TOTAL 9999.99
THE BELOW INFORMATION IS FROM LAB02 IF YOU NEED TO REFER BACK FOR LAB02 BECAUSE WE NEED TO USE IT FOR LAB03
OBJECTIVE
To demonstrate using input and output files
To demonstrate proper report formatting and spacing
To demonstrate summary totals
SPECIFICATIONS
Start with the LAB02 and copy in java statements from Lab01
Keep the input of the user name from the keyboard and the output message to the monitor
Make the following changes:
INPUT
Instead of accepting stock input from the keyboard, read it from an input file
Input file is
Lab02Input.txt (the following number is lab02input.txt)
42.87 23.33 2.10 EXC
12.00 83.33 0.17 ATVI
28.15 35.00 0.80 MSFT
42.98 23.26 0.65 CVS
33.64 29.72 2.20 TXN
55.51 18.01 2.00 NVS
16.00 62.50 0.40 SPLS
19.81 50.47 0.24 CSCO
30.09 33.23 1.76 T
39.29 25.45 0.60 DIS
18.65 53.00 0.29 SNE
50.21 19.21 0.72 AXP
102.69 9.74 1.44 NIK
Input record consists of the following fields:
Stock price (double)
Number of shares (double)
Annual dividend (double)
Stock ticker (String)
This file must be copied to the folder where you saved your Java program
PROCESS
You must add a loop because your program will read through and process the entire data file
Every time you go through the loop, you will read in a new record (set of data)
(Keep the processing for stock value and dividend yield)
Accumulate total stock value (goes in the loop)
OUTPUT
Output file to be created: Lab02Report.txt
Write a report heading (happens once, goes before the loop)
Write a column heading (happens once, goes before the loop)
Write a detail line for each stock (use printf) (happens once for each record, goes in the loop)
Write a summary line with the total stock value (use printf) (happens once, after the loop)
End report with a message and your name
output report (include blank lines)
in case if you need to look what lab01 look like the following below is Lab01
Start with the Java program Lab01
Add comments for: your name, date, purpose of the program
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.
-------------------------------------
I NEED ANSWER FOR LAB03
THANK YOU.
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