# Help making a very simple calculator?

• 01-26-2012, 04:21 AM
sfs
Help making a very simple calculator?
Hi, I'm very new to java I have been self teaching for about 3 days now and at the moment I am attempting to create a very simple calculator, however I have encountered a problem.

I'll show the code I've done first though:
Code:

``` import java.util.Scanner; public class calculatortest{   enum mathfunctions { Sum, Difference, Product, Quotient }               public static void main(String [] args){ Scanner input = new Scanner ( System.in );   mathfunctions a;   mathfunctions b;   mathfunctions c;   mathfunctions d;   String f;   double x;   double y;   double z;  a = mathfunctions.Sum;  b = mathfunctions.Difference;  c = mathfunctions.Product;  d = mathfunctions.Quotient;   System.out.print("Choose a mathematical function: Sum, Difference, Product, Quotient?");   f = input.nextmathfunctions(); // This is where the error is occuring. if(f.equals(a)){ System.out.print("Enter a value for x?"); x = input.nextDouble(); System.out.print("Enter a value for y?"); y = input.nextDouble(); z = x + y; System.out.print("The sum of the two values is: " + z ); } else if (f.equals(b)){ System.out.print("Enter a value for x?"); x = input.nextDouble(); System.out.print("Enter a value for y?"); y = input.nextDouble(); z = x - y; System.out.print("The difference of the two values is: " + z ); } else if(f.equals(c)){ System.out.print("Enter a value for x?"); x = input.nextDouble(); System.out.print("Enter a value for y?"); y = input.nextDouble(); z = x * y; System.out.print("The product of the two values is: " + z ); } else if(f.equals(d)){ System.out.print("Enter a value for x?"); x = input.nextDouble(); System.out.print("Enter a value for y?"); y = input.nextDouble(); z = x / y; System.out.print("The quotient of the two values is: " + z ); } } }```
The error I get is:

Code:

``` calculatortest.java:30: error: cannot find symbol f = input.mathfunctions(); symbol:  nextmathfunctions() location:  variable input of type scanner```
Can anyone help explain the problem for me?
• 01-26-2012, 04:27 AM
Fubarable
Re: Help making a very simple calculator?
You can't make up methods for a class (i.e., you're calling a nextmathfunctions() method on a Scanner object) and expect them to mathemagically work. Check out the Scanner API to see what methods are available to it, and only use those methods.
• 01-26-2012, 04:59 AM
sfs
Re: Help making a very simple calculator?
I realised I was making things way more complicated then they needed to be, so I got rid of the enums and worked it out. It's all working fine now thanks.