-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSet.java
More file actions
57 lines (55 loc) · 1.37 KB
/
Copy pathDataSet.java
File metadata and controls
57 lines (55 loc) · 1.37 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
package com.bleh.www;
import java.io.*;
import java.util.*;
/**
* This class allows the creation of a DataSet object that will hold header and
* integer array information for each file read in.
* @author connor
*
*/
public class DataSet {
private String header_;
private int[] data_;
/**
* Constructor to create a DataSet Instance.
* @param fileName is the name of the file.
* @throws Exception if the file cannot be opened.
*/
DataSet (String fileName) throws Exception {
Scanner scanIn = new Scanner(new FileInputStream (new File (fileName)));
header_ = scanIn.nextLine();
LinkedList<Integer> temp = new LinkedList<Integer>();
while (scanIn.hasNextInt()) {
temp.add(scanIn.nextInt());
}
data_ = new int[temp.size()];
for(int i =0; i<temp.size(); i++) {
data_[i] = temp.get(i);
}
}
/**
* A getter to retrieve the header of the input file.
* @return the header of the input file.
*/
public String getHeader() {
return header_;
}
/**
* A getter to retrieve the data of the input file.
* @return the data of the input file.
*/
public int[] getData() {
return data_;
}
/**
* A method to print the data/array of the data file out to a
* new file.
* @param ps is the PrintStream to be used.
*/
public void printData(PrintStream ps) {
ps.println(header_);
for(int i=0; i<data_.length; i++) {
ps.println(data_[i]);
}
}
}