?
Solved

using a count method.

Posted on 2005-03-05
6
Medium Priority
?
178 Views
Last Modified: 2010-03-31
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);
                            }
0
Comment
Question by:peterwittering
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 

Author Comment

by:peterwittering
ID: 13465581
i know

 }while (row <= 0);

should be

 }while (row <= rowCount);

just changed it for testing
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 13465602
it should be      while ( row <= rowCount-1 ) ; isn't it.

The reason is java is zero based index system.

Regards
Sudhakar
0
 

Author Comment

by:peterwittering
ID: 13465621
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:peterwittering
ID: 13465630
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 13465741
Firstly try changing

>>strMachineTV = tableValue.toString();


to

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

Author Comment

by:peterwittering
ID: 13465750
CEHJ .trim() removes  white spaces i presume?

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question