Results 1 to 5 of 5
  1. #1
    xwhysquared is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default Needs help Please

    I am getting cannot find symbol symbol : variable input for my app code
    and not a statement and the semicolon error message for my Class code

    App Code:

    class TestApp
    {

    public static void main (String args[ ])
    {




    //MyUtils obj = new MyUtils();


    int n1;
    int n2;
    int n3;
    int sum;
    int product;
    int average;
    int maximum;
    int minimum;


    System.out.println("Enter an int " );
    n1 =input.nextInt();

    System.out.println("Enter another int " );
    n2 =input.nextInt();

    System.out.println("Enter another int " );
    n3 =input.nextInt();


    sum = n1 + n2 + n3;
    product = n1 * n2 * n3;
    average = (n1 + n2 + n3 )/3;





    System.out.printf( "Sum is %d\n",sum );

    System.out.printf( "Product is %d\n",product );

    System.out.printf( "Average is %d\n",average );

    System.out.println( "Maximum is: " + maximum );
    System.out.println( "Minimum is: " + minimum );












    System.out.print sum (n1 , n2 , n3 );
    System.out.print product (n1 , n2 , n3 );
    System.out.print average (n1 , n2 , n3 );
    System.out.print( "Maximum is: " + maximum );
    System.out.print( "Minimum is: " + minimum );



    }


    }

    and Class Code:
    public class MyUtils
    {



    public static int sum(int n1, int n2, int n3)
    {
    int result;
    result = ( n1 + n2 + n3 );
    return result;
    }

    public static int product(int n1, int n2, int n3)
    {
    int result;
    result = (n1 * n2 * n3);
    return result;

    }

    public static int average (int n1, int n2, int n3)
    {
    int result;
    result = (n1 + n2 + n3)/3;
    return result;

    }

    public static int minimum (int n1, int n2, int n3);
    {
    int result ;
    result = minimum = n1;
    if ( n2 < minimum )
    minimum = n2;
    if ( n3 < minimum )
    minimum = n3;
    return result;


    }

    public static int max (int n1, int n2, int n3);
    {
    int result;
    result = maximum =n1;
    if ( n2 > maximum )
    maximum =n2;
    if ( n3 > maximum )
    maximum =n3;
    return result;
    }

    }
    any help or explanation would be appreciated

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    It's a good idea to post the complete compiler message.

    In the case of the TestApp main() method you do not declare input anywhere, so the compiler complains about the line

    Java Code:
    n1 =input.nextInt();

    Likewise you have undeclared variables in your minimum() and max() methods: minimum and maximum. You might find things less confusing if you make the method and variable names different, and keep the naimg consistent: so min()/max(), and minimum/maximum.

    (Also when you post code, use the "code" tags: put [code] at the start of your code and [/code] at the end.)

  3. #3
    xwhysquared is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default

    here the full compiler message first for the class code


    Java Code:
     C:\Users\jc\Documents\MyUtils.java:30: missing method body, or declare abstract
    		public static int minimum (int n1, int n2, int n3);
    		                  ^
    C:\Users\jc\Documents\MyUtils.java:33: cannot find symbol
    symbol  : variable minimum
    location: class MyUtils
    		result = minimum = n1;
    		         ^
    C:\Users\jc\Documents\MyUtils.java:33: cannot find symbol
    symbol  : variable n1
    location: class MyUtils
    		result = minimum = n1;
    		                   ^
    C:\Users\jc\Documents\MyUtils.java:34: cannot find symbol
    symbol  : variable n2
    location: class MyUtils
    		if ( n2 < minimum )
    		     ^
    C:\Users\jc\Documents\MyUtils.java:34: cannot find symbol
    symbol  : variable minimum
    location: class MyUtils
    		if ( n2 < minimum )
    		          ^
    C:\Users\jc\Documents\MyUtils.java:35: cannot find symbol
    symbol  : variable minimum
    location: class MyUtils
    			minimum = n2;
    			^
    C:\Users\jc\Documents\MyUtils.java:35: cannot find symbol
    symbol  : variable n2
    location: class MyUtils
    			minimum = n2;
    			          ^
    C:\Users\jc\Documents\MyUtils.java:36: cannot find symbol
    symbol  : variable n3
    location: class MyUtils
    		if ( n3 < minimum )
    		     ^
    C:\Users\jc\Documents\MyUtils.java:36: cannot find symbol
    symbol  : variable minimum
    location: class MyUtils
    		if ( n3 < minimum )
    		          ^
    C:\Users\jc\Documents\MyUtils.java:37: cannot find symbol
    symbol  : variable minimum
    location: class MyUtils
    			minimum = n3;
    			^
    C:\Users\jc\Documents\MyUtils.java:37: cannot find symbol
    symbol  : variable n3
    location: class MyUtils
    			minimum = n3;
    			          ^
    C:\Users\jc\Documents\MyUtils.java:38: return outside method
    		return result;
    		^
    C:\Users\jc\Documents\MyUtils.java:43: missing method body, or declare abstract
    		public static int maximum (int n1, int n2, int n3);
    		                  ^
    C:\Users\jc\Documents\MyUtils.java:46: cannot find symbol
    symbol  : variable maximum
    location: class MyUtils
    		result = maximum =n1;
    		         ^
    C:\Users\jc\Documents\MyUtils.java:46: cannot find symbol
    symbol  : variable n1
    location: class MyUtils
    		result = maximum =n1;
    		                  ^
    C:\Users\jc\Documents\MyUtils.java:47: cannot find symbol
    symbol  : variable n2
    location: class MyUtils
    		if ( n2 > maximum )
    		     ^
    C:\Users\jc\Documents\MyUtils.java:47: cannot find symbol
    symbol  : variable maximum
    location: class MyUtils
    		if ( n2 > maximum )
    		          ^
    C:\Users\jc\Documents\MyUtils.java:48: cannot find symbol
    symbol  : variable maximum
    location: class MyUtils
    			maximum =n2;
    			^
    C:\Users\jc\Documents\MyUtils.java:48: cannot find symbol
    symbol  : variable n2
    location: class MyUtils
    			maximum =n2;
    			         ^
    C:\Users\jc\Documents\MyUtils.java:49: cannot find symbol
    symbol  : variable n3
    location: class MyUtils
    		if ( n3 > maximum )
    		     ^
    C:\Users\jc\Documents\MyUtils.java:49: cannot find symbol
    symbol  : variable maximum
    location: class MyUtils
    		if ( n3 > maximum )
    		          ^
    C:\Users\jc\Documents\MyUtils.java:50: cannot find symbol
    symbol  : variable maximum
    location: class MyUtils
    			maximum =n3;
    			^
    C:\Users\jc\Documents\MyUtils.java:50: cannot find symbol
    symbol  : variable n3
    location: class MyUtils
    			maximum =n3;
    			         ^
    C:\Users\jc\Documents\MyUtils.java:51: return outside method
    		return result;
    		^
    24 errors
    Now for the App code
    Java Code:
     C:\Users\jc\Documents\TestApp.java:63: ';' expected
    System.out.print sum (n1  , n2 , n3  );
                        ^
    C:\Users\jc\Documents\TestApp.java:63: not a statement
    System.out.print sum (n1  , n2 , n3  );
                          ^
    C:\Users\jc\Documents\TestApp.java:63: ';' expected
    System.out.print sum (n1  , n2 , n3  );
                            ^
    C:\Users\jc\Documents\TestApp.java:63: not a statement
    System.out.print sum (n1  , n2 , n3  );
                                ^
    C:\Users\jc\Documents\TestApp.java:63: ';' expected
    System.out.print sum (n1  , n2 , n3  );
                                  ^
    C:\Users\jc\Documents\TestApp.java:63: not a statement
    System.out.print sum (n1  , n2 , n3  );
                                     ^
    C:\Users\jc\Documents\TestApp.java:63: ';' expected
    System.out.print sum (n1  , n2 , n3  );
                                       ^
    C:\Users\jc\Documents\TestApp.java:64: ';' expected
    System.out.print product (n1 , n2 , n3  );
                            ^
    C:\Users\jc\Documents\TestApp.java:64: not a statement
    System.out.print product (n1 , n2 , n3  );
                              ^
    C:\Users\jc\Documents\TestApp.java:64: ';' expected
    System.out.print product (n1 , n2 , n3  );
                                ^
    C:\Users\jc\Documents\TestApp.java:64: not a statement
    System.out.print product (n1 , n2 , n3  );
                                   ^
    C:\Users\jc\Documents\TestApp.java:64: ';' expected
    System.out.print product (n1 , n2 , n3  );
                                     ^
    C:\Users\jc\Documents\TestApp.java:64: not a statement
    System.out.print product (n1 , n2 , n3  );
                                        ^
    C:\Users\jc\Documents\TestApp.java:64: ';' expected
    System.out.print product (n1 , n2 , n3  );
                                          ^
    C:\Users\jc\Documents\TestApp.java:65: ';' expected
    System.out.print average (n1 , n2 , n3  );
                            ^
    C:\Users\jc\Documents\TestApp.java:65: not a statement
    System.out.print average (n1 , n2 , n3  );
                              ^
    C:\Users\jc\Documents\TestApp.java:65: ';' expected
    System.out.print average (n1 , n2 , n3  );
                                ^
    C:\Users\jc\Documents\TestApp.java:65: not a statement
    System.out.print average (n1 , n2 , n3  );
                                   ^
    C:\Users\jc\Documents\TestApp.java:65: ';' expected
    System.out.print average (n1 , n2 , n3  );
                                     ^
    C:\Users\jc\Documents\TestApp.java:65: not a statement
    System.out.print average (n1 , n2 , n3  );
                                        ^
    C:\Users\jc\Documents\TestApp.java:65: ';' expected
    System.out.print average (n1 , n2 , n3  );
                                          ^
    21 errors

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    C:\Users\jc\Documents\MyUtils.java:30: missing method body, or declare abstract
    public static int minimum (int n1, int n2, int n3);

    This one refers to the code

    Java Code:
    public static int minimum (int n1, int n2, int n3)[b];[/b]  // <--- the ; should not be there
    {

    The maximum() method has a similar problem.

    The "symbol not found" messages relate to the undeclared variables I talked about before.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Java Code:
    System.out.print sum (n1 , n2 , n3 );
    System.out.print product (n1 , n2 , n3 );
    System.out.print average (n1 , n2 , n3 );

    These three lines from the main() method don't make any sense and are responsible for the compiler errors from the TestApp class.

Posting Permissions

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