Java - elements in an array problem, help please

Permabanned
Joined
18 Nov 2011
Posts
368
Location
Aberystwyth
Hello, at the moment, the method I'm using currently returns whats left in the array as strings rather than an int count.

so lets say I had 4 cards left in the game it would return

4 diamonds, 5 spades, ace clubs, queen diamonds.

[4d.gif, 5s.gif, ac.gif, qd.gif]

However, I need to add to the method so that it counts those elements left and returns them as an int, which in this case would be 4. That would be the score for the game.

Anyone be able to give me some sort of help on this situation please? If possible with an explanation, not just the answer, as then I won't learn anything, which is the whole purpose. :)

Example

public int size()
{
return graphicCard.size();
}

System.out.println("The number of elements in the array are:" +graphicCard+ "");
 
Right, i solved that problem. Now i need to be able to write to file with the score I have obtained.

public void save (String scoreList) throws IOException {
PrintWriter outfile = new PrintWriter (new OutputStreamWriter

(new FileOutputStream(scoreList)));
outfile.println(graphicCard.size());
for (Game c:cards) {
outfile.println(c.toString());
}
outfile.close();
}

So far i have used the following. Any ideas where i've gone wrong. I've put the error in bold. The error stated;

cannot find symbol - variable cards
 
Back
Top Bottom