• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Assignment problem for school

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


can someone please help me with this
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chris McBurn wrote:
can someone please help me with this



Do you have a specific question/issue/concern that you are addressing?


[EDIT: Oh I see. You are asking about a compiler error message. Hint. The "=" and the "==" operators are two different operators]

Henry
 
Chris McBurn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I GOT IT. thanks mate.
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for trying to UseCodeTags (that's a link) but you didn't quite get it. The code goes between the tags. I often just highlight the code and press the code button.
 
Marshal
Posts: 8515
615
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Chris, I'd suggest you to re-think your problem and the method you have constructed (topUp). Such a method I'd expect to see with boolean return type. And the logic would be:

2. I'm not sure you fixed the issue Henry pointed out, but never again write "while (ok == false)" or while (ok == true) as it is error-prone, where it is easy enough to make a mistake. Change to "while (ok)". Of course we could debate if variable name "ok" is good or not, but mostly of the guys probably would say latter. So, you could try to think a better name for the situation.
 
Marshal
Posts: 76845
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never use == false or == true, which are not only error‑prone (you have fallen into that trap yourself) but also poor style.
Not
while (b == true) ...
but
while (b) ...
Not
while (b == false) ...
but
while (!b) ...
The local variable never used warnings tell me you are using Eclipse (probably at too early a stage in your career) and you have yet to work out how much of what it tells you can be ignored You might do well to print those messages and forget about the return type and change that method to void type.
 
Campbell Ritchie
Marshal
Posts: 76845
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A boolean return type as Liutauras suggests is a good alternative.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic