Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Simple Calculator help needed- modifying to accept up to 3 inputs  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help with editing the calculator class so that it can calculate values such as 8+2+4 or 6-2+21 etc...
I know i need a new something to store the third input and that the inEquals method in the calculator class needs to be modified to account for it, but any attemps ive made to do this results in wrong calculations
or it not reading the third input at all.

calculator class

Posts: 63781
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please always use the code button; since you are new I have edited your post, and doesn't it look better.

Let's forget the GUI for the time being. That is only display. You need to look at the heart of the app, the calculator. Please explain what you are doing. You need to explainwhat you are doing before you will have any idea of how to do it. It should be possible to pass values to the calculator like this:-Once you have got that sort of thing working, you can consider:-
  • 1: What sort of input you are getting from your GUI.
  • 2: How to create that sort of input.
  • 3: How to get the result back so you can display it.
  • How is your inDigit() method in line 12 supposed to work? You don't usually get your input from a GUI digit by digit. You get the whole number as text, which needs to be converted to a number.
    Why have you got so many ifs? Why don't you use a switch?
    Have you been through the Java® Language Specification? It is surprising, but that section includes an example of a calculator. If Oracle are going to put it on a website, and you happen to find it, why not modify it from double arithmetic to integer arithmetic and use it?
    Power corrupts. Absolute power xxxxxxxxxxxxxxxx is kinda neat.
    global solutions you can do in your home or backyard
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!