I want to read from a txt file and I am using System.arraycopy to copy
parts[] to scores[].
I know that scores must be a String in order to work. My
constructor has to be an int[] array for scores. So scores is an int[]. Is there any solution?
private void processLine(String line) {
String mygoden1 = "";
//String mygoden2 = "";
try {
String parts [] = line.split(",");
mygoden1= parts[0];
Name name = new Name(parts[1]);
int gN1=Integer.parseInt(mygoden1);
String gL= parts[3];
//gL = gL.trim();
String gC = parts[4];
gC=gC.trim();
int scoresLength = parts.length-4;
String scores[]=new String[scoresLength];
System.arraycopy(parts,4,scores, 0, scoresLength);
Gamer g1 = new Gamer(gN1 ,name,scores, gL, gC);
this.add(g1);
}
This is my constructor:
public class Gamer {
private int gnumb; //The Gamers Number g -> is for gamer
private Name gamerName;
private String glevel;
private String gCountry;
private static final int SCORES_1 =5;
private int [] scores;
//}
public Gamer(int gN ,Name name, int gS[], String gL , String gC)
{
gnumb = gN;
gamerName=name;
scores = new int [SCORES_1];
scores=gS;
glevel =gL;
gCountry =gC;
}
I would replace
with