# Help with a calculator

• September 9th, 2012, 05:22 PM
Joshroark10
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
• September 9th, 2012, 05:39 PM
jps
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?
• September 9th, 2012, 06:22 PM
Joshroark10
Re: Help with a calculator
like 4x+3=11, i had to make separate code for each one like

Quote:

public static void main(String[] args) {

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

System.out.print("Enter first number : ");

System.out.print("Enter number to add by : ");

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

System.out.println(x);

}
}

For each one, i want to combine it all so its all in one class
• September 10th, 2012, 03:44 AM
jps
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).
• September 10th, 2012, 03:34 PM
Joshroark10
Re: Help with a calculator
Yes this is just for basic ones.
• September 10th, 2012, 03:59 PM
Zaphod_b
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