• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Which is correct

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and yet another basic, I'm a slow learner question.

Which of the two are right, or does it matter. And if it does matter what is the guideline.

the pseudocode is:





or



The sumOfBeginningBalances is the variable I'll be working with in this method.

Thanks
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it depends on whether you're updating sumOfBeginningBalances or the method currentAccount.getBalance(). what preceded this in the pseudocode? this will affect what you'll do. my gut suggests your second option but w/o the benefit of the specifications it is only a guess.
 
Richard Chambers
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's the million dollar question.

In the application I'm working with multiple accounts, and the sumOfBeginningBalances it the total for all accounts. In this method, I'm working with only one of those accounts.

I'm "guessing" I'm updating the sum.

I'm sure I'm microanalizing too much. Until I get the beginningBalance it's initialized at 0.0, so it updates, but the sum is also 0.0 until it updates the first time.


This is the first line of this method BTW.

Also, I'll throw in another question, for when I get this done.

In a conditional coding, if I want both conditons to be true before it does the statement that's "&"?

& checks both conditions?
&& stops if first is false?

Thanks
[ April 13, 2008: Message edited by: Richard Chambers ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the first question, only the second one is legal Java. The left operand of the "+=" operator must be a variable. Since you've got a sum, and want to add more to it, then the second one is not only the legal one, but also the one that makes sense.

For the second question both operators will do the right thing, but "&&" will do less work in some cases. For both of these, the controlled statement will only be executed if both the conditions are true. The difference is that "&" will always execute both conditions. The "&&" operator will say "Hey, the first condition was false, so I don't care what the second one evaluates to, since it doesn't matter; I'm not going to execute the statement no matter what, so I'll just skip it."
 
Richard Chambers
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks

just a little more clarification on the +=

if I'm using two variables, which one updates,
the left or right.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Richard Chambers:
...just a little more clarification on the +=

if I'm using two variables, which one updates, the left or right.


a += b is just shorthand for a = a + b.
 
Richard Chambers
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So b += a

would be b = b + a then?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic