Accumulators

Reply

Join Date: Aug 2007
Posts: 58
Reputation: NycNessyness is an unknown quantity at this point 
Solved Threads: 0
NycNessyness NycNessyness is offline Offline
Junior Poster in Training

Accumulators

 
0
  #1
May 23rd, 2008
Hello guys. I'm having a bit of difficulty with adding totals. I know how it's suppose to work but I'm not seeing what I'm doing wrong. If I want to add my total each time I hit the total button how can I do it. When I try to add it, it never works but lets say I do total = total +10;, it will do it only once no matter how many times I press the total button. This is an example of the code I have for now. So basically with this code, anytime I hit the total button it should keep adding 5 to the total. So the first time it will be 5, second time 10 and so forth. Thanks in advance!

  1. total = 5;
  2. newtotal = 0.0;
  3.  
  4. public void actionPerformed(ActionEvent e)
  5. {
  6. String arg = e.getActionCommand();
  7.  
  8.  
  9.  
  10. if(arg == "Total")
  11. {
  12. total = total + newtotal;
  13. }
  14. }
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,363
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 500
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Accumulators

 
0
  #2
May 23rd, 2008
Um, you can 0 to a value all day and it won't change...
  1. total = 5;
  2. newtotal = 0.0;
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 58
Reputation: NycNessyness is an unknown quantity at this point 
Solved Threads: 0
NycNessyness NycNessyness is offline Offline
Junior Poster in Training

Re: Accumulators

 
0
  #3
May 23rd, 2008
I tried newtotal; instead of newtotal = 0; also and it didn't work.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,363
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 500
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Accumulators

 
0
  #4
May 23rd, 2008
I would imagine that you are either resetting total or newtotal is not being captured like you think it is, because there is nothing wrong with that operation (except that you could use total += newtotal; instead).
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 58
Reputation: NycNessyness is an unknown quantity at this point 
Solved Threads: 0
NycNessyness NycNessyness is offline Offline
Junior Poster in Training

Re: Accumulators

 
0
  #5
May 23rd, 2008
I found out what I had to do. It's lame when you find out you make the simplest of mistakes. I needed to add an extra line newtotal = total;. Then everytime i pick the total button it adds the old total to the new total. My new code with it implemented is below, incase others may have the same question in the future. Thanks again Ezz.

  1. total = 5;
  2. newtotal = 0.0;
  3.  
  4. public void actionPerformed(ActionEvent e)
  5. {
  6. String arg = e.getActionCommand();
  7.  
  8.  
  9.  
  10. if(arg == "Total")
  11. {
  12. total = total + newtotal;
  13. newtotal = total;
  14. }
  15. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC