Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Initialize ArrayList w / Variable

$
0
0
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.


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?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>