Can someone show me how to set up getters and setters for this 2D ArrayList?
public class PureRatings {
private List<List<Integer>> pureRatingsList;
I’m not sure if this part is right…
public PureRatings() throws IOException {
pureRatingsList = parseRatingsFile();
}
Here is the code for the rest of the 2D ArrayList, I didn’t know if I should include it or not…
public static List<List<Integer>> parseRatingsFile() throws IOException {
List<List<Integer>> pureRatings = new ArrayList<List<Integer>>();
BufferedReader in = new BufferedReader(new FileReader("Ratings.txt"));
String ratingsLine = null;
while ((ratingsLine = in.readLine()) != null) {
pureRatings.add(parseRatingsLine(ratingsLine));
}
in.close();
return pureRatings;
}
public static List<Integer> parseRatingsLine(String ratingsLine) throws IOException {
List<Integer> ratings = new ArrayList<Integer>();
if (ratingsLine == null) {
return ratings;
}
String[] ratingsStrArr = ratingsLine.split(" ");
try {
for (final String ratingStr : ratingsStrArr) {
ratings.add(Integer.parseInt(ratingStr));
}
} catch (NumberFormatException e) {
System.out.println(e.getMessage());
}
return ratings;
}
}
1 Answer