Hi everyone! I am having trouble with the ArrayList. I have never really dealt with them but I have to use them for my next project. I will post my code here.
In the second public BusStop() method, my assignment says I need to initialize lines with numLines Line objects in array lines but I do not understand what that means or even how to do that. If somebody could help me out it would be much appreciated! Do I need to use a for loop?
import java.util.ArrayList;
public class BusStop extends Location {
protected java.util.ArrayList<Line> lines = null;
public BusStop() {
lines = new ArrayList<Line>();
}
public BusStop(java.lang.String name, int x, int y) {
super(name, x, y);
lines = new ArrayList<Line>();
}
public BusStop(java.lang.String name, int x, int y, Line[] lines, int numLines) {
super(name, x, y);
//this is where I need to initialize lines with numLines Line objects in array lines
}
public void addLine(Line line) {
this.lines.add(line);
}
}
In the second public BusStop() method, my assignment says I need to initialize lines with numLines Line objects in array lines but I do not understand what that means or even how to do that. If somebody could help me out it would be much appreciated! Do I need to use a for loop?