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,colum n);
strMachineTV = tableValue.toString();
if (strMachineTV.equals(strMa chine)){
count++;
row++;
}
else{
row++;
}
}
catch (NullPointerException e) {
row++;
}
catch (ArrayIndexOutOfBoundsExce ption 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 (ArrayIndexOutOfBoundsExce ption e) {
}
}while (machineCount <= 11);
}
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,colum
strMachineTV = tableValue.toString();
if (strMachineTV.equals(strMa
count++;
row++;
}
else{
row++;
}
}
catch (NullPointerException e) {
row++;
}
catch (ArrayIndexOutOfBoundsExce
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 (ArrayIndexOutOfBoundsExce
}
}while (machineCount <= 11);
}
it should be while ( row <= rowCount-1 ) ; isn't it.
The reason is java is zero based index system.
Regards
Sudhakar
The reason is java is zero based index system.
Regards
Sudhakar
ASKER
if (strMachineTV.equals(strMa chine)){
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??
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??
ASKER
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 :(
Help
objects CEHJ :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
CEHJ .trim() removes white spaces i presume?
its works, now i know my whole algorith is crap ;)
its works, now i know my whole algorith is crap ;)
ASKER
}while (row <= 0);
should be
}while (row <= rowCount);
just changed it for testing