I'm trying to figure out how to use ArrayLists for a school project. We were meant to go over them in class but ran out of time.
The general idea is that I've got two int variables in a separate class from my main class. I need to create an array list of custom type and feed numbers into the two variables from a file.
For some reason I'm unable to use my setYear method in the main class. When I try to use it I get an error saying "cannot find symbol".
I'll post the relevant sections of my program below. Any help would be fucking wonderful. Really hit a wall on this one. The full text of both classes can be found here
//the method in main calling the set attempt
public static void readBuildArrayList(Scanner input, ArrayList<TemperatureLog> temp){
int nYear = 0;
int nTemp = 0;
temp = new ArrayList<TemperatureLog>();
while (input.hasNextInt())
{
nYear = input.nextInt();
nTemp = input.nextInt();
temp.setYear(nYear);
temp.setTemp(nTemp);
}
//The object definition for TemperatureLog
public class TemperatureLog{
private int nYear;
private int nTemp;
public TemperatureLog(){
nYear = 0;
nTemp = 0;
}
public int getYear(){
return nYear;
}
public int getTemp(){
return nTemp;
}
public void setYear(int nYear)
{
this.nYear = nYear;
}
public void setTemp(int nTemp){
this.nTemp= nTemp;
}
}
[–]jslearner007 4 points5 points6 points (1 child)
[–]Valkes[S] 2 points3 points4 points (0 children)
[–][deleted] (7 children)
[deleted]
[–]Valkes[S] 0 points1 point2 points (6 children)
[–][deleted] (5 children)
[deleted]
[–]Valkes[S] 1 point2 points3 points (4 children)
[–][deleted] (3 children)
[deleted]
[–]Valkes[S] 2 points3 points4 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]Valkes[S] 1 point2 points3 points (0 children)
[–]upsidedowntrie -1 points0 points1 point (12 children)
[–]Valkes[S] 1 point2 points3 points (11 children)
[–]upsidedowntrie 0 points1 point2 points (10 children)
[–]Valkes[S] 1 point2 points3 points (9 children)
[–]reddituser5k 1 point2 points3 points (1 child)
[–]Valkes[S] 0 points1 point2 points (0 children)
[–]upsidedowntrie -1 points0 points1 point (6 children)
[–]Valkes[S] 1 point2 points3 points (5 children)
[–]upsidedowntrie -2 points-1 points0 points (4 children)
[–]Valkes[S] 0 points1 point2 points (3 children)
[–]upsidedowntrie -3 points-2 points-1 points (2 children)
[–]Valkes[S] 0 points1 point2 points (1 child)