/** * * The class models a Stock object * * Name: * Course: * Section: * Last Modified: * Known Bugs: */ import java.io.*; public class Stock { // identify Stock instance variables double [] A = new double[365]; double currentPrice; int tradingDays; // Default constructor set up an empty Stock object // Second constructor (with parameters)accepts a File of stock prices as input and read the file into the array. public Stock(String fileName){ FileInput myFile = new FileInput(fileName); tradingDays = 0; while (!myFile.eof()) { String temp = myFile.getString(); int k = temp.indexOf(" "); String date = temp.substring(0,k-1); String next = temp.substring(k); next = next.trim(); k = next.indexOf(" "); String hi = next.substring(0,k-1); next = next.substring(k); next = next.trim(); k = next.indexOf(" "); String lo = next.substring(0,k-1); next = next.substring(k); next = next.trim(); k = next.indexOf(" "); String closingPrice = next.substring(0,k-1); double price = Double.parseDouble(closingPrice); A[tradingDays++] = price; } currentPrice = A[tradingDays-1]; } // sort Sorts the array of numbers in ascending order (code given) public void sort(){ for (int i=0; i A[j+1]) { double temp = A[j]; A[j] = A[j+1]; A[j+1] = temp; } } // max Returns the maximum closing stock price for the year public double max(){ // do not sort // complete code } // min Returns the minimum closing stock price for the year public double min(){ // do not sort // complete code } // mean Returns the mean closing stock price for the year public double average(){ // do not sort // complete code } // median Returns the median closing stock price for the year public double median(){ sort(); // complete code // Hint : to check tradingDays is even use // if (tradingDays%2==0) etc.. // median is the average of the two middle elements // if size is even and if size is odd, then it is the middle // element } // ROI compute the return on investment return a percentage as a double (+ or -) public double ROI(){ // do not sort here // ROI is the (end price - start price)/start price) *100 } // print the list public void print(){ // print stock prices in each line } }