Link to home
Start Free TrialLog in
Avatar of peterwittering
peterwittering

asked on

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);
                            }
Avatar of peterwittering
peterwittering

ASKER

i know

 }while (row <= 0);

should be

 }while (row <= rowCount);

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

The reason is java is zero based index system.

Regards
Sudhakar
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??
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 :(
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
CEHJ .trim() removes  white spaces i presume?

its works, now i know my whole algorith is crap ;)