# Thread: Help making a very simple calculator?

1. Member Join Date
Jan 2012
Posts
2
Rep Power
0

## 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:
Java 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:

Java 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?
Last edited by sfs; 01-26-2012 at 03:28 AM.  Reply With Quote

2. ## 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.  Reply With Quote

3. Member Join Date
Jan 2012
Posts
2
Rep Power
0

## 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.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•