This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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

 
Greenhorn
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
**************************************************************



 
Marshal
Posts: 62881
203
  • 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?
     
    All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
    RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
    https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!