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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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"); } } }

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education