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 1 of 1

Thread: How to get a sum value from items listed in array ?

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to get a sum value from items listed in array ?

    What's wrong with my code? I am trying to write a basic shopping cart but I need some help in coding the payment button, which should display the SUM value of the items listed in array.The program is compiling but I am getting some errors msgs in the console like these:
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
     
    	----
    		if (e.getSource() == btnPayment){
    			int sum  = 0;
    			for (int i=0; i < pickedCars.length; i++){
    				sum = (int) (sum + pickedCars[i].getValue());
    				txfTotal.setText("Your payment so far is: " + sum);
                                   }
    			}
    Last edited by makarov; January 9th, 2010 at 06:37 PM. Reason: not getting any help at all.


Similar Threads

  1. Arrays: question about "removing" items.
    By sanfor in forum Collections and Generics
    Replies: 2
    Last Post: November 30th, 2009, 04:09 AM
  2. Object array to int array?
    By rsala004 in forum Collections and Generics
    Replies: 1
    Last Post: October 30th, 2009, 04:09 AM
  3. Storing an array into an array
    By vluong in forum Collections and Generics
    Replies: 4
    Last Post: September 22nd, 2009, 02:14 PM
  4. Different operation on Array
    By jempot in forum Collections and Generics
    Replies: 4
    Last Post: January 27th, 2009, 06:07 AM