Results 1 to 3 of 3
- 01-26-2012, 03:21 AM #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:
The error I get is: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 ); } } }
Can anyone help explain the problem for me?Java Code:calculatortest.java:30: error: cannot find symbol f = input.mathfunctions(); symbol: nextmathfunctions() location: variable input of type scanner
Last edited by sfs; 01-26-2012 at 03: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.
- 01-26-2012, 03:59 AM #3
Member
- 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: 09-18-2011, 01:37 PM -
Simple Calculator
By marksey07 in forum New To JavaReplies: 12Last Post: 01-09-2011, 06:30 AM -
Re: Simple Calculator cont'd
By JavaHater in forum New To JavaReplies: 3Last Post: 01-07-2011, 02:00 AM -
Help making calculator with TextArea
By matrixcool in forum AWT / SwingReplies: 9Last Post: 12-15-2010, 02:56 AM -
Help making a calculator
By karl_koch_89 in forum New To JavaReplies: 3Last Post: 08-27-2010, 02:47 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks