Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: probably a simple noob problem

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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++)
    {
     
            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 ++;
     
        }                                        
            }


  2. #2
    Member
    Join Date
    Feb 2011
    Posts
    55
    My Mood
    Tolerant
    Thanks
    1
    Thanked 16 Times in 15 Posts

    Default 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

  3. The Following User Says Thank You to JJeng For This Useful Post:

    JavaPF (February 23rd, 2011)

Similar Threads

  1. Simple problem...
    By _lithium_ in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 6th, 2011, 12:02 AM
  2. Simple beginers problem
    By vycka1990 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 18th, 2010, 12:00 PM
  3. Simple Actionlistener problem
    By olemagro in forum AWT / Java Swing
    Replies: 5
    Last Post: October 11th, 2010, 10:46 AM
  4. Simple import problem
    By Mekster in forum Java IDEs
    Replies: 3
    Last Post: November 13th, 2009, 09:17 PM
  5. Simple scanner problem
    By Sinensis in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: September 20th, 2009, 09:01 PM