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.
for (int i = 0; i < dataSize; i++)
float money, time;
time = Float.parseFloat(jTextField1.getText());
money = Float.parseFloat(jTextField2.getText());
double tutMoney = (money);
double tutTime = (time);
array [dataSize] = (tutTime);
array [dataSize] = (tutMoney);
String tutTimesting = ("" + tutTime);
String tutMoneystring = ("" + tutMoney);
double totalTime = 0;
totalTime = array [dataSize] + (totalTime);
String totalTimestring = ("" + totalTime);
jTextArea1.append ("Total time ");
double totalMoney = 0;
totalMoney = array [dataSize] + (totalMoney);
String totalMoneystring = ("" + totalMoney);
jTextArea1.append ("Total money earned ");
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 :)