Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot find symbol

 
ahmad mohmmad
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody
please help me in this program i do not what is the wrong :

Server :


public class RECT
{
private int len ;
private int wed ;
public RECT()
{

len = 0 ;
wed = 0 ;

}

public void setlen(int x)
{
len = x ;
}

public void setwed( int x )
{
wed = x ;
}

public int getlen()
{
return len ;

}

public int getwed()
{
return wed ;

}

public int area()
{
return len * wed ;

}

public String toString()
{

String x = "" ;

x = x + len + "\n" ;
x = x + wed ;

return x ;

}

}



Client :


public class S1
{
public static void main (String[]args)

{


RECT R1 = new RECT() ;



System.out.println(R1.getlen()) ;
System.out.println(R1.getwed()) ;

R1.setlen(5) ; R1.setwed(12) ;

System.out.println (R1) ;
System.out.println ("the area is " + area ) ;

}


}



and the result after compile the client :

C:\Users\User7\Documents\S1.java:18: cannot find symbol
symbol : variable area
location: class S1
System.out.println ("the area is " + area ) ;
^
1 error

Tool completed with exit code 1


 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and welcome to the Ranch!

Please read UseCodeTags (<-click). By following the directions given, your code will be easier to read, thus increasing your chances of getting a good answer.

As for your issue, the error message you get is pretty straightforward. You are trying to print the value of variable area but you haven't declared it. However, you can get an area of the rectangle by invoking area() method on an instance of the class representing a rectangle. The method is invoked as: classInstance.methodName().

I would also point you to review Java Programming Style Guide and follow it when writing your code.
 
ahmad mohmmad
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer
ok..can you give me the Solution
and where i should put the code? (which line ) ?

many thanks
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahmad mohmmad wrote:can you give me the Solution

That's not how we do things here. We are NotACodeMill <-click and we expect you to ShowSomeEffort <-click.

Oh, and welcome to the Ranch!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12127
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is your code with the 'code tags' being used. See how much easier it is to read and understand? I had to re-format it. Don't mix tabs and spaces - that just makes it a hot mess.

FWIW, 'x' is really a terrible variable name. Unless it is something completely trivial (like a loop index), you have no idea what it is supposed to represent.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic