0

I am currently making a voting system where the voter enters in their details such as name, age etc. I also have another class for admin, the admin can view the list of results but i also want the admin to edit the voter details and to save the edit. this is what i have so far:

public void EditVoterAccounts()
{
    int i=0;
    for (Voters vote: Voters.listVoters)
    {
        System.out.println(i + "  " + vote.getName());
    }
}

Also another problem is the list of the voters come up as all 0. For example, it should show up like this:

0 voter
1 second voter
3 third.

but what I am getting is this:

0 voter
0 second voter
0 third 

which I am guessing will confuse the system

Guillaume Jacquenot
  • 11,217
  • 6
  • 43
  • 49

1 Answers1

1

You've forgotten to increment the counter.

    public void EditVoterAccounts()
    {
        int i = 0;
        for (Voters vote: Voters.listVoters)
        {
            System.out.println(i + "  " + vote.getName());
            i++;
        }
    }
  • thank you very much its working however its displaying the results twice for some reason, do you know how i can fix this? – JustABeginner Dec 04 '16 at 14:41
  • The code sample that I provided prints one line for each element in listVoters. So either you are calling it twice, or listVoters contains duplicates. Try running it in debug mode, place a breakpoint inside the loop and see what's going on. – Coderslang Master Dec 04 '16 at 15:36