[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

Error message (cannot resolve symbol)

Hi Folks, I'm having trouble getting my head around the error that I'm experiencing.
I know its only simple but until I can nail it it keeps nagging me.
Some code:-

//Numbers    


public class Numbers
{
     public static void main(String[] args)
     {
          int when, now;     //declare variables
          when=45;
          now=15;
         
          sum=calcSum(when, now);
          diff=calcDiff(when, now);
          prod=clacProd(when, now);
          System.out.println("Total is: " + sum);
          System.out.println("Difference is: " + diff);
          System.out.println("Product is: " + prod);
     }
     public static int calcSum(int w, int n)
     {
          int totSum;     //add the variables
          totSum=(w + n);
          return totSum;
     }
     public static int calcDiff(int w, int n)
     {
          int totDiff;     //get the difference
          totDiff=(w % n);
          return totDiff;
     }
     public static int calcProd(int w, int n)
     {
          int totProd;     //multiply the variables
          totProd=(w * n);
          return totProd;
     }
         
}    

This is some of the errors,

                ^
Numbers.java:14: cannot resolve symbol
symbol  : method clacProd  (int,int)
location: class Numbers
                prod=clacProd(when, now);
                     ^
Numbers.java:15: cannot resolve symbol
symbol  : variable sum
location: class Numbers
                System.out.println("Total is: " + sum);
                                                  ^
As you can see they are similar errrors, so I only need to get this and I'll be able to nail another concept(hopefully).
Regards Ned
0
Ned_Kelly
Asked:
Ned_Kelly
  • 2
  • 2
1 Solution
 
Ned_KellyAuthor Commented:
This piece of code is very similar and it works, the maths might not be perfect but the app works.

//Picture

public class Picture
{
     public static void main(String[] args)
     {
          float height, width;     //declare types
          float cost, glass, met, squ;    
         
          squ=0.56f;     //Square is $56 divided by 1000 number of square cm
          met=28.50f;     //meter is $28.50 per lineal meter
          height=17.9f;
          width=24.6f;
          cost=calcCost(height, width);
          glass=calcGlass(height, width);
          System.out.println("Frame cost is: " + cost);
          System.out.println("Glass cost is: " + glass);
          System.out.println("Total cost for the picture is: " + (cost + glass) / 100 * 10);
     }
     public static float calcCost(float h, float w)
     {
          float totCost;
          totCost=(h * 2 + w * 2) * 28.50f;
          return totCost;
     }
     public static float calcGlass(float h, float w)
     {
          float totGlass;
          totGlass=(h * w) * 0.56f;
          return totGlass;
     }
}

Regards Ned
0
 
yongsingCommented:
Here are your problems:

>> Numbers.java:14: cannot resolve symbol
>> symbol  : method clacProd  (int,int)
>> location: class Numbers
>>                prod=clacProd(when, now);
                    ^
The function name is "calcProd", not "clacProd"!

>> Numbers.java:15: cannot resolve symbol
>> symbol  : variable sum
>> location: class Numbers
>>                System.out.println("Total is: " + sum);
                                                 ^
The variables sum, diff, and prod are not defined. You should rewrite the statements as:

int sum=calcSum(when, now);
int diff=calcDiff(when, now);
int prod=clacProd(when, now);
0
 
yongsingCommented:
The last statement should be:

int prod = calcProd(when, now);

Also, you have a mistake in your calcDiff() method:

totDiff=(w % n);

You should change the % to a - sign.
0
 
Ned_KellyAuthor Commented:
Thats great, thankyou yongsing, you were right in both instances.  The % sign was put there thinking that it was the difference that I wanted, not to worry.
I'm still not sure why the other app works though, is it because of the f behind the numbers in the code below.

  squ=0.56f;    
                                                             met=28.50f;    
                                                             height=17.9f;
                                                             width=24.6f;
                                                             cost=calcCost(height, width);
                                                             glass=calcGlass(height, width);

Or is it because its a different type.
Thanks again for a great answer.
Regards Ned
0
 
vasan_srCommented:
Hello sir,
   U have to declare the variable, and then use the variable.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now