i'm a beginner in java and i have these codes for my voting system:
public void Result_Election(){
int vote1=Vote_President();
String pres1="Theo";
String pres2="William";
String pres3="Maxon";
String pres4="Douglas";
int n1=0, n2=0, n3=0, n4=0;
try{
PrintWriter i=new PrintWriter(new FileWriter("voting_score.txt", true));
if (vote1==1){
int[] addVotes = {1};
for (int add : addVotes){
result[add-1]+=1;
n1=result[add-1];
}
i.println(pres1+" "+n1);
}
else if (vote1==2){
int[] addVotes = {2};
for (int add : addVotes){
result[add-1]+=1;
n2=result[add-1];
}
i.println(pres2+" "+n2);
}
else if (vote1==3){
int[] addVotes = {3};
for (int add : addVotes){
result[add-1]+=1;
n3=result[add-1];
}
i.println(pres3+" "+n3);
}
else if (vote1==4){
int[] addVotes = {4};
for (int add : addVotes){
result[add-1]+=1;
n4=result[add-1];
}
i.println(pres4+" "+n4);
}
i.close();
}catch (Exception e){
}
}
my problem is the output. every time i add votes to one candidate, it will add another name with its incremented votes. but i want is just one name per candidate and every time i add up votes to one candidate, it won't add another name. just the number of vote. please help