Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Help with a calculator

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    3
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with a calculator

    I have been trying to make a algebraic equation solver. I have all my code i made a GUI i just need to know how to combine the code it is all seprate for addition&multiplacation etc. and how to put the code to the gui


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help with a calculator

    1+1=2?

    Without seeing the code, and a clearer question, not much advice to offer.
    What do you mean combine the code?
    What do you mean put the code to the gui?

    You say you have "all my code" ... what do you have?

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    3
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with a calculator

    like 4x+3=11, i had to make separate code for each one like

    public static void main(String[] args) {
    Scanner reader = new Scanner(System.in);

    double a;
    double b;
    double x;
    double c;
    double r;

    System.out.print("Enter first number : ");
    a = reader.nextDouble();

    System.out.print("Enter number to add by : ");
    b = reader.nextDouble();

    System.out.print("Enter answer: ");
    c = reader.nextDouble();

    r = (c - b);
    x = (r / a);

    System.out.print("Your answer is: ");
    System.out.println(x);









    }
    }

    For each one, i want to combine it all so its all in one class

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help with a calculator

    You need to think in terms of reusable code. Surely you don't expect to hard code a solution for all possible algebraic expressions, (as that is an infinite number).

  5. #5
    Junior Member
    Join Date
    Sep 2012
    Posts
    3
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with a calculator

    Yes this is just for basic ones.

  6. #6
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: Help with a calculator

    The title that you gave the thread is "Help with a calculator," but the project you described is an equation solver.

    Which is it?

    I mean a calculator would (somehow) have user input like 2.3 + 3.4 * 4.5 (maybe with an '=' to indicate that it's time to show the results). If that were the kind of program you are talking about, there would be a few questions:

    Are there precedence rules? Are there parentheses? Stuff like that.


    Whereas you have described user input in the form 4x+3=11 (With some kind of input to indicate that it's time to solve for x.)

    So the question, as jps implied, is: What form of user input are you going to allow? Is it always in the form ax+b = c where a, b, and c are user inputs and x will be the solution (assuming a solution exists)?

    If it is, then the calculation part is (almost) finished: You simply have a function that has three parameters: a, b, c, that are (presumably) double precision floating point numbers and that returns the value that your posted code can calculate. (Don't forget to test to make sure the user didn't enter zero for a.)

    On the other hand, are there more complicated equations that will be allowed? What are they? How does the program know what the user is entering. Or, more to the point: How does the user know what kind of data and how many data values are required (or allowed)? Is it supposed to handle quadratic equations? Other non-linear stuff? What???



    Cheers!

    Z

Similar Threads

  1. [SOLVED] Calculator
    By ikocijan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 26th, 2012, 05:54 AM
  2. Calculator Using AWT
    By Allicat in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 17th, 2011, 06:49 AM
  3. Calculator
    By Andrew Wilson in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2011, 08:08 AM
  4. Calculator
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 22nd, 2010, 09:00 AM
  5. [SOLVED] Calculator help
    By Bradshjo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 1st, 2010, 04:27 PM