Modify java code for Hw5 (stock,each csv file has headings: Date,Open,High,Low,Close, Adj Close,Volume) to count and print the number of days there is gain (increase from open to close price) of 2% or more of stock price. Also count and print the number of days the High is 30% bigger than Low. Also, find and print the average volume for the trading days where there is gain. Make sure each print occupies a single line, and all lines are lined up such that the label for each information requested is left aligned, and the decimal points are all aligned. import java.util.*; import java.io.*; public class StockData { public static double average(ArrayList prices) { double total = 0; double average; for (int i = 0; i < prices.size(); i++) { total = total + prices.get(i); } if (prices.size() > 0) { average = total / prices.size(); return average; } else { return 0; } } public static double min(ArrayListprices) { double min = prices.get(0); for (int i = 1; i < prices.size(); i++) { if (min > prices.get(i)) { min = prices.get(i); } } return min; } public static double max(ArrayListprices) { double max = prices.get(0); for (int i = 1; i < prices.size(); i++) { if (max < prices.get(i)) { max = prices.get(i); } } return max; } public static double standardDev(ArrayListprices) { double total = 0; for(int i = 0; i < prices.size(); i++) { double subtract = prices.get(i) - average(prices); double numerator = Math.pow(subtract, 2); total = total + numerator; } double divison = total / (prices.size() - 1); double stDev = Math.sqrt(divison); return stDev; } public static void main(String [] args) throws FileNotFoundException{ Scanner in = new Scanner(System.in); System.out.println("Enter stock symbol: "); String stock = in.next(); stock = stock.toUpperCase(); try { File inputFile = new File(stock + ".csv"); Scanner stockFile = new Scanner(inputFile); //stockFile.useDelimiter(","); stockFile.nextLine(); //skip the header line ArrayList prices = new ArrayList(); while (stockFile.hasNextLine()) { String line = stockFile.nextLine(); String [] data = line.split(","); String price = data[4]; //closing price double p = Double.parseDouble(price); prices.add(p); } stockFile.close(); System.out.printf("Average price: %8.2f \n", average(prices)); System.out.printf("Minimum price: %8.2f \n", min(prices)); System.out.printf("Maximum price: %8.2f \n", max(prices)); System.out.printf("Standard Deviation: %6.2f \n", standardDev(prices)); } catch(FileNotFoundException e) { System.out.println("File not found."); } catch(NumberFormatException e) { System.out.println("Number fo
Modify java code for Hw5 (stock,each csv file has headings: Date,Open,High,Low,Close, Adj Close,Volume) to count and print the number of days there is gain (increase from open to close price) of 2% or more of stock price. Also count and print the number of days the High is 30% bigger than Low. Also, find and print the average volume for the trading days where there is gain. Make sure each print occupies a single line, and all lines are lined up such that the label for each information requested is left aligned, and the decimal points are all aligned.
import java.util.*; import java.io.*; public class StockData { public static double average(ArrayList<Double> prices) { double total = 0; double average; for (int i = 0; i < prices.size(); i++) { total = total + prices.get(i); } if (prices.size() > 0) { average = total / prices.size(); return average; } else { return 0; } } public static double min(ArrayList<Double>prices) { double min = prices.get(0); for (int i = 1; i < prices.size(); i++) { if (min > prices.get(i)) { min = prices.get(i); } } return min; } public static double max(ArrayList<Double>prices) { double max = prices.get(0); for (int i = 1; i < prices.size(); i++) { if (max < prices.get(i)) { max = prices.get(i); } } return max; } public static double standardDev(ArrayList<Double>prices) { double total = 0; for(int i = 0; i < prices.size(); i++) { double subtract = prices.get(i) - average(prices); double numerator = Math.pow(subtract, 2); total = total + numerator; } double divison = total / (prices.size() - 1); double stDev = Math.sqrt(divison); return stDev; } public static void main(String [] args) throws FileNotFoundException{ Scanner in = new Scanner(System.in); System.out.println("Enter stock symbol: "); String stock = in.next(); stock = stock.toUpperCase(); try { File inputFile = new File(stock + ".csv"); Scanner stockFile = new Scanner(inputFile); //stockFile.useDelimiter(","); stockFile.nextLine(); //skip the header line ArrayList<Double> prices = new ArrayList<Double>(); while (stockFile.hasNextLine()) { String line = stockFile.nextLine(); String [] data = line.split(","); String price = data[4]; //closing price double p = Double.parseDouble(price); prices.add(p); } stockFile.close(); System.out.printf("Average price: %8.2f \n", average(prices)); System.out.printf("Minimum price: %8.2f \n", min(prices)); System.out.printf("Maximum price: %8.2f \n", max(prices)); System.out.printf("Standard Deviation: %6.2f \n", standardDev(prices)); } catch(FileNotFoundException e) { System.out.println("File not found."); } catch(NumberFormatException e) { System.out.println("Number format error"); } } }
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)