Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You\'ve been hired by Microsoft Monarchs to write a Java console application tha

ID: 3730100 • Letter: Y

Question


You've 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 Date Close Volume Open High Data type String double int double double Purpose Trading date Ending share value on that day Number of shares traded during that day. Starting share value on that day Highest share value on that day Lowest share value on that day double Low 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: e 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. e 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:

Explanation / Answer

Code of main, readTextFile, printData, analyzeData

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

class StockDataAnalyzer {

  

public String DateAray[];

public double Close[];

public int Volume[];

public double Open[];

public double High[];

public double Low[];

public long totalFileData=0;

public int size=4;

  

public static void main(String[] args) {

  

StockDataAnalyzer stockData = new StockDataAnalyzer();

stockData.DateAray = new String[stockData.size];

stockData.Close = new double[stockData.size];

stockData.Volume = new int[stockData.size];

stockData.Open = new double[stockData.size];

stockData.High = new double[stockData.size];

stockData.Low = new double[stockData.size];

stockData.readTextFile(stockData);

stockData.printData(stockData);

stockData.analyzeData(stockData);

  

}

public void readTextFile(StockDataAnalyzer objStockData)

{

int i=0;

BufferedReader reader;

try

{

reader = new BufferedReader(new FileReader("MicrosoftStockData.txt"));

String line = reader.readLine();

while (line != null)

{   

line = reader.readLine();

String[] data = line.split(",");

if(data.length>0 && i<objStockData.size)

{

objStockData.DateAray[i]=data[0];

objStockData.Close[i]= Double.parseDouble(data[1]);

objStockData.Volume[i]= Integer.parseInt(data[2]);

objStockData.Open[i]=Double.parseDouble(data[3]);

objStockData.High[i]=Double.parseDouble(data[4]);

objStockData.Low[i]=Double.parseDouble(data[5]);

}

i++;

objStockData.totalFileData++;

  

}

reader.close();

}

catch (IOException e)

{

e.printStackTrace();

}

}

public void printData(StockDataAnalyzer objStockData)

{

int i=0;

System.out.println(objStockData.totalFileData+" data lines read from 'MicrosoftStockData.txt'");

System.out.println("First 12 days of data ranging from"+objStockData.DateArray[0]+" - "+objStockData.DateArray[3]);

System.out.println("Date"+" "+"Close"+ " "+"Volume"+" "+"Open"+" "+"High"+" "+"Low");

System.out.println();   

for(i=0;i<4;i++)

{

System.out.print(objStockData.DateAray[i]+" "+objStockData.Close[i]+objStockData.Volume[i]+" "+objStockData.Open[i]+" "+objStockData.High[i]+" "+objStockData.Low[i]);

System.out.println();

}

}

  

public void analyzeData(StockDataAnalyzer objStockData)

{

double HighestData = objStockData.Close[0];

double lowestData=objStockData.Close[0];

int indexH=0;

int indexL=0;

for(int i=1;i < objStockData.Close.length;i++)

{

if(objStockData.Close[i] > HighestData)

{

HighestData = objStockData.Close[i];

indexH=i;

}

if(objStockData.Close[i] < lowestData)

{

lowestData = objStockData.Close[i];

indexL=i;

}

  

}

System.out.println("Highest closing stock data date: "+objStockData.DateArray[indexH] +" and volume: "+objStockData.Volume[indexH]);

System.out.println("Lowest closing stock data date: "+objStockData.DateArray[indexL] +" and volume: "+objStockData.Volume[indexL]);

double HighestDiffrence = objStockData.High[0]-objStockData.Low[0];

indexH = 0 ;

for(int i=1;i < objStockData.Close.length;i++)

{

if((objStockData.High[i]-objStockData.Low[i])>HighestDiffrence)

{

HighestDiffrence = objStockData.High[i]-objStockData.Low[i];

indexH=i;

}

}

System.out.println("Highest diffrence date: "+objStockData.DateArray[indexH] +" and value: "+ HighestDiffrence);

}

  

  

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote