-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileIO.java
More file actions
79 lines (66 loc) · 1.65 KB
/
Copy pathFileIO.java
File metadata and controls
79 lines (66 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Write a description of class FileIO here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.io.*;
import java.util.*;
public class FileIO
{
private String fileName;
private String[] dates;
private double[] data;
private double currentPrice;
private double lowPrice;
private double highPrice;
public FileIO(String file) throws FileNotFoundException {
fileName = file;
System.out.println("Scanning file" + fileName);
Scanner input = new Scanner(new File(file));
int index = 0;
dates = new String[100];
data = new double[100];
while(input.hasNextLine()) {
String line = input.nextLine();
String[] words = line.split(", ");
System.out.println(Arrays.toString(words));
dates[index] = words[0];
data[index] = Double.parseDouble(words[1]);
index++;
}
currentPrice = data[0];
double max = data[1];
for(int i=2; i<data.length;i++){
if(data[i]>max){
max = data[i];
}
}
highPrice = max;
double min = data[1];
for(int i=2; i<data.length;i++){
if(data[i]<min){
min = data[i];
}
}
lowPrice = min;
}
public String[] getDates(){
return dates;
}
public double[] getData(){
return data;
}
public double getHigh(){
return highPrice;
}
public double getLow(){
return lowPrice;
}
public double getCurr(){
return currentPrice;
}
public String getFileName(){
return fileName;
}
}