How to get a sum value from items listed in array ?
Quote:
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)
Code :
----
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);
}
}