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

Creating array from constructor

$
0
0
Hello, I know this is a very basic question but I would appreciate so help in determining why my constructor is not creating an array for me.

Here is the code:

	public static void main(String[] args) {

		DoubleArraySeq sequence;
		sequence = new DoubleArraySeq();

		
		for(int i = 0; i < sequence.length; i++){
			sequence[i] = i;
		}
		sequence.toString();
	}
}




Also,

public class DoubleArraySeq {

private double[] data;
private int manyItems;
private int currentIndex;

public DoubleArraySeq() {
super();
final int INITIAL_CAPACITY = 10;
manyItems = 0;
data = new double [INITIAL_CAPACITY];

}



public String toString(){
StringBuffer buffer = new StringBuffer();
buffer.append("Scores: [");
for (double item : data){
buffer.append(item + " ");
}
buffer.append("]");
return buffer.toString();
}

public class DoubleArraySeq {

private double[] data;
private int manyItems;
private int currentIndex;

public DoubleArraySeq() {
super();
final int INITIAL_CAPACITY = 10;
manyItems = 0;
data = new double [INITIAL_CAPACITY];

}


public String toString(){
StringBuffer buffer = new StringBuffer();
buffer.append("Scores: [");
for (double item : data){
buffer.append(item + " ");
}
buffer.append("]");
return buffer.toString();
}



Viewing all articles
Browse latest Browse all 51036

Trending Articles



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