• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Incompatible types error

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Helo I've been struggling for hours now!! I'm doing a java course and I must code an interactive balancing calculator! my textbook does not explain the work very nice so now I'm stuck!!!
This is what I coded but when I compile they give me 4 errors saying incompatible types! I don't know what I'm doing and I feel so stupid!! Please help!!

 
Marshal
Posts: 79953
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which book are you using, and how old is it?
Why are you using Readers, rather than a Scanner? A Scanner will give the input directly converted to the Java™ type required. Rather than your reading the line as a String and trying to assign that to the openingBalance amount, which is a double, so the compiler cannot achieve that (hence your error message), you can get the input converted directly without having to mess about with parseXXX method. So you can get the input in the correct type for money, which is not float nor double, but BigDecimalAnd there is a serious error in that code. So as not to let people think you are getting that code without any effort, I shall "forget" to correct that error (which appears twice). And I have respelt some of your variable names.
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic