Results 1 to 3 of 3
  1. #1
    sfs
    sfs is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default 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 04:28 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  3. #3
    sfs
    sfs is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default 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.

Similar Threads

  1. Trying to make simple calculator
    By Buldogg in forum New To Java
    Replies: 1
    Last Post: 09-18-2011, 02:37 PM
  2. Simple Calculator
    By marksey07 in forum New To Java
    Replies: 12
    Last Post: 01-09-2011, 07:30 AM
  3. Re: Simple Calculator cont'd
    By JavaHater in forum New To Java
    Replies: 3
    Last Post: 01-07-2011, 03:00 AM
  4. Help making calculator with TextArea
    By matrixcool in forum AWT / Swing
    Replies: 9
    Last Post: 12-15-2010, 03:56 AM
  5. Help making a calculator
    By karl_koch_89 in forum New To Java
    Replies: 3
    Last Post: 08-27-2010, 03:47 AM

Posting Permissions

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