using a count method.

I have created the folowing method to analyse the results of the lottery machines,  however the count is always 0, the vector is created correctly and I can create the table but the value of times used is alway 0 for the 12 machines, table has 12 rows , which is correct with the different machine name.

Whats wrong with this algorithm? I think its not running the if statement to add on 1 to the count correct?

public static void createMResults(){
        row = 0;
        column = 9;
        machineCount = 0;
        machine = new Vector();
        rowCount = table.getRowCount();
                       
                       //reads all balls!      
                       do{
                        count = 0;
                        row = 0;
                        machineCount++;
                                   try{
                                    if (machineCount == 1){
                                    strMachine = "AMETHYST";}
                                    else if (machineCount == 2){
                                    strMachine = "MOONSTONE";}
                                    else if (machineCount == 3){
                                    strMachine = "OPAL";}
                                    else if (machineCount == 4){
                                    strMachine = "TOPAZ";}
                                    else if (machineCount == 5){
                                    strMachine = "GARNET";}
                                    else if (machineCount == 6){
                                    strMachine = "PEARL";}
                                    else if (machineCount == 7){
                                    strMachine = "LANCELOT";}
                                    else if (machineCount == 8){
                                    strMachine = "ARTHUR";}
                                    else if (machineCount == 9){
                                    strMachine = "GALAHAD";}
                                    else if (machineCount == 10){
                                    strMachine = "GUINEVERE";}
                                    else if (machineCount == 11){
                                    strMachine = "MERLIN";}
                                    else if (machineCount == 12){
                                    strMachine = "VYVYAN";}
                        //reads one ball!                                                                  
                                                                                    do{
                                                                                    try{
                                                                                    tableValue = table.getValueAt(row,column);
                                                                                    strMachineTV = tableValue.toString();
                                                                                    if (strMachineTV.equals(strMachine)){
                                                                                    count++;
                                                                                    row++;
                                                                                    }
                                                                                    else{
                                                                                    row++;
                                                                                    }
                                                                                    }
                                                                                    catch (NullPointerException e) {
                                                                                    row++;
                                                                                    }
                                                                                    catch (ArrayIndexOutOfBoundsException e) {
                                                                                    row++;
                                                                                    }
                                                                                    }while (row <= 0);
                                //problem here!! out of bounds exception
                                Vector machineSet = new Vector();
                                machineSet.add(new String(strMachine));
                                machineSet.add(new Integer(count));
                                machine.add(machineSet);
                                }
                                catch (NullPointerException e) {
                                }
                                catch (ArrayIndexOutOfBoundsException e) {
                                }
                                }while (machineCount <= 11);
                            }
peterwitteringAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

peterwitteringAuthor Commented:
i know

 }while (row <= 0);

should be

 }while (row <= rowCount);

just changed it for testing
0
sudhakar_koundinyaCommented:
it should be      while ( row <= rowCount-1 ) ; isn't it.

The reason is java is zero based index system.

Regards
Sudhakar
0
peterwitteringAuthor Commented:
if (strMachineTV.equals(strMachine)){
count++;
row++;
}

that works fine the problem is here, I have used system.out.println and is just not rcognising when the equal or I am resetting cout to soon??
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

peterwitteringAuthor Commented:
i have commented out the points i reset count add its still not adding up so the error is in the .equals if statement but can i hell see why!!

Help

objects CEHJ :(
0
CEHJCommented:
Firstly try changing

>>strMachineTV = tableValue.toString();


to

strMachineTV = tableValue.toString().trim();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peterwitteringAuthor Commented:
CEHJ .trim() removes  white spaces i presume?

its works, now i know my whole algorith is crap ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.