Here is my code:
class Catandmouse {
public void CatAndMouse() {
Animal cat = new Animal();
Animal mouse = new Animal();
int mouseCaught = (int) (Math.random() * 10);
cat.CatchMouse();
int catgetsit = 0;
if ( mouseCaught == cat.number ) {
System.out.println("The cat caught the mouse!");
}
else {
System.out.println("The mouse got away!");
}
}
}
Here is my Animal class:
class Animal {
public void CatchMouse() {
int number = (int) (Math.random() * 10);
}
}
And this is the error:
CatAndMouse.java:8: cannot find symbol
symbol : variable number
location: class Animal
if ( mouseCaught == cat.number ) {
^
1 error
Why the error?
Reply quick. Also explain the error