Re: please help me



mak wrote:
Hi , I am mak and i have a great problem with a java application . May
i hava your help , please?The program is called INCRTest.java and
calls class INCR.java.The main program sums an increment value and
puts it into a variable called total.
INCRTest.java is as follows:
public class INCRTest{
public static void main(String[] args){
INCR value=new INCR(5);
System.out.printf("prin ayxhthei : %s\n\n",value);
for(int i=1;i<=3;i++){
value=addINCRToTotal();
System.out.printf("meta thn ayxhsh %d: %s\n",i,value);

}
}
}
, INCR.java is as follows:
public class INCR{
private int total=0;
private final int INCREMENT;
public INCR(int incrementValue){
INCREMENT= incrementValue;
}
public void addINCRToTotal(){
total+=INCREMENT;
}
public String toString(){
return String.format("total= %d",total);
}
}

Compliler says that he 'cannot find symbol method addINCRToTotal()'

You should /copy/ and /paste/ the /entire/ error message. In this case, though, the answer is obvious. You invoked
value=addINCRToTotal();
which embodies three errors:

1) addINCRToTotal() was not invoked through an owning object.
2) addINCRToTotal() does not return anything, therefore you cannot put it in an expression such as an assignment.
3) value is an object of type INCR (better to name that class Incr, btw) and not of what you probably thought the return type of addINCRToTotal() should have been (were it not void).

The compiler error was your clue - you have defined no symbol addINCRToTotal() in the context of the test class.

--
Lew
.



Relevant Pages

  • Re: *p++ = *q++ undefined? why?
    ... void strcpy(char *s, char *t) ... As far as I can see, the assignment expression here will 'run' like ... increment s then t, OR, increment t then s. ...
    (comp.lang.c)
  • Re: incrementing void *
    ... void *ptr; ... Which of the following is the correct way to increment the variable ... sizeof (myArray) referrs to the whole ... C does not define arithmetic on void* pointers (though ...
    (comp.lang.c)
  • Re: incrementing void *
    ... answer to 'what is the correct way to increment a void* variable' is ... is a carefully-defined macro); 1, 4, and 5 all try to do arithmetic on ... would use in some cases if it were portable, obviously using myStruct* ...
    (comp.lang.c)
  • Re: Simple Recursion
    ... only the last node will be incremented because the increment will ... you would have used a debugger it would be easy to see why this function ... One way to fix that function is this: ... void List::addOne ...
    (comp.lang.cpp)
  • Testing for an empty directory with readdir
    ... is empty in a opendir/readdir/closedir scheme? ... increment a counter for every thing that readdir finds, and if it gets to 2 ... printAllFileInfo(void){ ...
    (comp.unix.programmer)