Quote (waraholic @ 25 Jun 2017 09:47)
The way your professor wants you to do it is:
Scanner stdIn = new Scanner(new File("C:/temp/tmps.txt"));
List<Double> numbers = new ArrayList<>();
while(stdIn.hasNext()) {
numbers.add(new Double(stdIn.next()));
}
The more functional way to do it would be like:
Path p = Paths.get("C:", "temp", "tmps.txt");
Stream<String> lines = Files.lines(p);
I ended up using scanner for the file read, but for some reason I couldn't get it to read past the first line. The way you have it makes sense but I wouldn't have thought of it because we haven't done arrays.
Code
Scanner inputReader = new Scanner(System.in);
System.out.println("Enter total system cost in dollars");
int sysTotal = inputReader.nextInt();
Scanner stdIn = new Scanner(new File("energyProduced.txt"));
double energy;
energy = stdIn.nextDouble();
I tried that which wouldn't read past line one in the .txt. Obviously I have no real clue what I am doing lol, so it's pretty sloppy.
This post was edited by sbc'soneandonly on Jun 25 2017 10:38am