Question
Youve been hired by Microsoft Monarchs to write a Java console application that analyzes their stock data over the past eleven years. Use text file
Youve been hired by Microsoft Monarchs to write a Java console application that analyzes their stock data over the past eleven years. Use text file MicrosoftStockData.txt as input to the application. The first line of the file contains the column headers. The rest of the lines contain daily Microsoft stock data. Values are separated by commas into the following columns:
Column | Data type | Purpose |
Date | String | Trading date |
Close | double | Ending share value on that day. |
Volume | int | Number of shares traded during that day. |
Open | double | Starting share value on that day. |
High | double | Highest share value on that day. |
Low | double | Lowest share value on that day. |
Here are the first five lines of the file:
date,close,volume,open,high,low
3/5/2018,93.64,23787950,92.34,94.27,92.26
3/2/2018,93.05,32815660,91.58,93.15,90.86
3/1/2018,92.85,36979700,93.99,94.57,91.84
2/28/2018,93.77,30011960,94.84,95.705,93.63
The application reads the data into arrays, prints the first several rows of the data, and then analyzes and charts the data. Create the following functions:
main this function defines one array for each column of data in the input file such that there are six parallel arrays. It then calls these functions in sequence: readTextFile, printData, analyzeData, and chartData.
readTextFile this function reads each line of the file, parses it into six columns, and stores each token in its respective array. It skips past the first line which contains the column headers.
printData this function prints two header lines. The first indicates the range of dates in the data. The second shows the column headers. It then prints the first twelve lines of the data. Here is sample output:
analyzeData this function determines the following:
(1) The date and value of the highest daily stock closing value.
(2) The date and value of the lowest daily stock closing value.
(3)The date and highest difference between the daily high and low stock values.
(4) The closing value of the stock on the latest day of each year. For 2018, this is March 5. For each of the other ten years, this is December 31. Store the years and closing values in two parallel arrays. These arrays may then be used to print and chart this data.
It then prints the yearly closing values (4) formatted in two columns:
The year.
The closing value.
It then prints the highest (1), lowest (2), and differences (3) formatted in three columns:
A label.
A date.
A closing value or difference.
Format all real numbers to two decimal places. For the following functions, use the JFreeChart library. This was discussed in the Session 12 Notes. See the Chart drawing sample application on Blackboard.
chartData this function charts the closing value of the stock on the latest day of each year. The chart is a line chart with the year along the x-axis and the stock value along the y-axis. It calls function createPanel, places the panel in a frame, and shows the frame.
createPanel this function call functions createDataset and createChart. It uses class DefaultCategoryDataset instead of class PieDataset.
createDataset this function uses class DefaultCategoryDataset instead of class PieDataset. It also uses the arrays created when determining the closing value of the stock on the latest day of each year.
createChart this function uses class createLineChart instead of class createPieChart. See web pages www.jfree.org/jfreechart/api/gjdoc/org/jfree/chart/ChartFactory.html#createLineChart:String:String:String:CategoryDataset:PlotOrientation:boolean:boolean:boolean and www.tutorialspoint.com/jfreechart/jfreechart_line_chart.htm for more information.
Here is what the chart should look like:
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