Results 1 to 3 of 3
 01262012, 04:21 AM #1Member
 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 ); } } }
Java Code:calculatortest.java:30: error: cannot find symbol f = input.mathfunctions(); symbol: nextmathfunctions() location: variable input of type scanner
Last edited by sfs; 01262012 at 04:28 AM.

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.
 01262012, 04:59 AM #3Member
 Join Date
 Jan 2012
 Posts
 2
 Rep Power
 0
Similar Threads

Trying to make simple calculator
By Buldogg in forum New To JavaReplies: 1Last Post: 09182011, 02:37 PM 
Simple Calculator
By marksey07 in forum New To JavaReplies: 12Last Post: 01092011, 07:30 AM 
Re: Simple Calculator cont'd
By JavaHater in forum New To JavaReplies: 3Last Post: 01072011, 03:00 AM 
Help making calculator with TextArea
By matrixcool in forum AWT / SwingReplies: 9Last Post: 12152010, 03:56 AM 
Help making a calculator
By karl_koch_89 in forum New To JavaReplies: 3Last Post: 08272010, 03:47 AM
Bookmarks