probably a simple noob problem
Hi all, this is my first post. I am writing a simple program for a class, and can't get my data to fill the loop properly. Everytime I click enter ti resets my variables so i keep filling the same positions in the array.
Code Java:
for (int i = 0; i < dataSize; i++)
{
dataSize ++;
float money, time;
time = Float.parseFloat(jTextField1.getText());
money = Float.parseFloat(jTextField2.getText());
double tutMoney = (money);
double tutTime = (time);
//array
array [dataSize][0] = (tutTime);
array [dataSize][1] = (tutMoney);
{
jTextArea1.append("Minutes: ");
String tutTimesting = ("" + tutTime);
jTextArea1.append(tutTimesting);
jTextArea1.append(" ");
jTextArea1.append("Earnings: ");
String tutMoneystring = ("" + tutMoney);
jTextArea1.append (tutMoneystring);
jTextArea1.append("\n");
}
{
double totalTime = 0;
totalTime = array [dataSize][0] + (totalTime);
String totalTimestring = ("" + totalTime);
jTextArea1.append ("Total time ");
jTextArea1.append (totalTimestring);
jTextArea1.append ("\n");
}
{
double totalMoney = 0;
totalMoney = array [dataSize][1] + (totalMoney);
String totalMoneystring = ("" + totalMoney);
jTextArea1.append ("Total money earned ");
jTextArea1.append (totalMoneystring);
jTextArea1.append ("\n");
}
dataSize ++;
}
}
Re: probably a simple noob problem
Issues that I see:
1.The for loop looks never ending, dataSize is incremented twice in the loop thus making 'i' forever smaller than dataSize.
2. For loop condition seems off by 1,arrays start at 0
3. You have an additional bracket in the code segment here.
Probably a copy paste error.
4. Total variable scope issues
I'd make sure you check the scope of the dataSize to make sure the method isn't resetting its value every time the method is called. I don't know if the code blocks are supposed to be in the for loop, but since they are, the total isn't being added up correctly because of the scope of the 'total' variables.
In the future, please try to make your code blocks a bit more legible by fixing indents and matching brackets. My first post too. Hello peoples :)