public class ICMA42

   // instance variables - replace the example below with your own
   private int alpha;
   private int bravo;
   private int sum;

   /**
    * Constructor for objects of class sum which initialises sum to 0.
    */
   public ICMA42()
   {
      this.alpha = 0;
      this.bravo = 0;
      this.sum = alpha + bravo;
   }

   /**
    * Sets the value of alpha to the receiver to the value of the argument aAlpha.
    */
   public void setAlpha (int aAlpha)
   {
      this.alpha = aAlpha;
   }

   /**
    * find the sum of the two int type arguments and store the result in a local variable called sum 
    */
   public void sumArgs()
   {
     if (sum > 10)
   {
      System.out.println("Sum is " + this.sum);
   }
   }
}

Output - cannot find symbol - method setAlpha(int)

That message was generated by some other piece of code - if you don't post that then nobody can help.
ps Your sumArgs method makes absolutely no sense whatsoever.

That's all the source code I have. I'm using BlueJ.

Yeah I know none of it makes sense, it's for an assignment.

Let's take this one step at a time:
Exactly which line of code does the error message refer to? (Post the whole error message - don't edit or summarise it)

How do you use setAlpha() method? It is a member method, so you can't simply use it without initiate an instance of the class first. Please show the part where you call the method.

Sorry

Code Pane

ICMA42 pete = new ICMA42();
pete.sumArgs();
this.setAlpha(42);

Display Pane

Compilation failed (10/12/2014 17:54:33)
Error: line 3 - cannot find symbol - method setAlpha(int)

setAlpha is an instance method of the ICMA42 class. To call it you need an instance of ICMA42.

In your this.setAlpha the this refers to the current instance of whatever class that code was in, which obviously isn't ICMA42. That's what the error is syaing - whatever class this is doesn't have a setAlpha method.
The way you called sumArgs is the correct way to do it.

Ok, in the source code how would I resolve this?

The way you called sumArgs is the correct way to do it.

I'm trying to set aplha and bravo as values to enable to me to add them together to get a value for sum

yes, but what is the problem? just replace
this by pete, as James already said.

I get the idea.
Your test code creates an instance of ICMA42 and uses that to call ICMA's sumArgs method. That method is nonsense, but the way you call it is 100% correct.
You need to use the same instance of ICMA42 to call your setAlpha method. Not this, which is some other instance entirely.

To give you better understanding of the issue i have here is the question:

This question requires you to write code for a simple method as part of a class ICMA42. Your method should:

be in the public protocol of the class ICMA42
have the name sumArgs
receive two int type arguments
find the sum of the two int type arguments and store the result in a local variable called sum
if the sum of the arguments is more than 10, the method should display the text "Sum is X", where X is the sum of the arguments.
If the sum of the arguments is between 1 and 10 inclusive, the method should display the text "Sum is X" sum times.
return the String "positive" if the sum of the arguments is more than 0,
return the String "negative" if the sum of the arguments is less than 0,
return the String "zero" if the sum of the arguments is equal to 0.

Ths needs to be done using BlueJ

erictheonly: we understand the issue. James has already explained why it fails, and how to correct it.

"This needs to be done using BlueJ" -> this is irrelevant. code is not IDE dependent.

i cannot use the instance pete instead of this in my source code as it does not recognise it.

EDIT: sorry, ignore that comment

Code Pane

ICMA42 pete = new ICMA42();
pete.sumArgs(); <<<<<<<<<<<<<<<<<<< recognises "pete"
this.setAlpha(42); <<< if you use pete here "it" will recognise it

Yes, just got that after i typed my dumbass previous comment.

I execute that but it does not seem to give me any output. It should set alpha as 42 thus triggering the sum to be > 10 and giving me a comment.

Aside from the usage of pete, the compiling issue could just be the missing { after public class ICMA42.

No it's present, it just hasn't copied over onto the above

OK.
If you look at your code you will see:
the setAlpha method just sets that variable. It does not do anything to update the sum. You are still missing some of the code you were supposed to write.

Maybe this is your problem (or maybe not)
sum = alpha + bravo;
this does not define sum. It's an instruction that is executed as part of the method it's in. If you change alpha or bravo you need to execute that instruction (or one just like it) again. It would be great if you could define sum to be aplpha+bravo automatically whatever/whenever alpha or bravo are set, but that's not how it works.

When I add:

public void setAlpha (int aAlpha)
   {
      this.alpha = aAlpha;
      this.update("sum");

     }

It highlights the .update and says cannot find symbol - method update(java.lang.String)

It won't let me see page 2, thank you all for your help it has certainly got me further along.

EDIT: just showed me page 2 after this comment - technology is not my friend today.

EDIT2: played around with it and my code looks like this now:

/**
    * Sets the value of alpha to the receiver to the value of the argument aAlpha.
    */
   public void setAlpha (int aAlpha)
   {
      this.alpha = aAlpha;
      this.sum = alpha + bravo;
   }

This works and I removed the 'this.sum = alpha + bravo;' at the top.

EDIT 3: Also adding the same line of code of bravo has enabled both input to result in the correct variable for the sum output.

Just need to figure out the final part.

I've added this:

   /**
    * find the sum of the two int type arguments and store the result in a local variable called sum 
    */
   public void sumArgs()
   {
     if (sum > 10)
     {
      System.out.println("Sum is " + this.sum);
     }
     if ((sum >= 1) && (sum <= 10))
     {
      System.out.println("Sum is " + this.sum);
     }
   }

and want the second if statement to print out the value of sum as many times as the variable of sum.

use a for loop

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.