So I'm working on an assignment for a class in Java, and am having a problem getting scan.nextLine to fill the array of objects. Of course scan.nextLine is giving a String and the object array can't take that. The assignment specifies that the array must be of objects and that each part of the array is filled with an entire line from the file being read. Thanks for any help! It does have to be Temperature objects as it's used in a class later.
Scanner scan = new Scanner(new File("Temperatures.txt"));
int n = scan.nextInt() + 1;
Temperature[] Temperature = new Temperature[n];
String dd = scan.nextLine();
for (int i = 0; i < n; i++) {
Temperature[i] = scan.nextLine();
}
System.out.println(Temperature[n - 1]);
System.out.println(Temperature[0]);
return Temperature;
}
I have tried casting to the object and that did not work.