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
Printable View
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
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?
like 4x+3=11, i had to make separate code for each one like
Quote:
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
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).
Yes this is just for basic ones.
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