I keep on getting "error: cannot find symbol" for class Frog whenever I compile class Pond, even though there is no such error with class Fly.
Main class, Pond:
package flyFrogPond;
public class Pond {
public static void main(String args[]) {
Frog frogPeepo = new Frog("Peepo");
Frog frogPepe = new Frog("Pepe", 10, 15);
Frog frogPeepaw = new Frog("Peepaw", 4.6, 5);
Frog frogPeepue = new Frog("Peepue");
Fly fly1 = new Fly(1, 3);
Fly fly2 = new Fly(6);
Fly fly3 = new Fly();
Frog.setSpecies("1331 Frogs");
frogPeepo.toString();
frogPeepo.eat(fly2);
fly2.toString();
frogPeepo.grow(8);
frogPeepo.eat(fly2);
fly2.toString();
frogPeepo.toString();
frogPeepue.toString();
frogPeepaw.grow(4);
frogPeepaw.toString();
frogPepe.toString();
}
}
Class Frog:
package flyFrogPond;
public class Frog{
private String name;
private int age;
private double tongueSpeed;
private boolean isFroglet;
private static String species;
private double ageInYears;
public static void setSpecies( String Species){ species = Species;}
public Frog(String Name){
name = Name;
age = 5;
tongueSpeed = 5;
isFroglet = (age < 7 & age > 1) ? true : false;
species = "Rare pepe";
}
public Frog(String Name, double AgeInYears, double TongueSpeed){
name = Name;
ageInYears = AgeInYears;
tongueSpeed = TongueSpeed;
age = (int) (ageInYears * 12);
isFroglet = (age < 7 & age > 1) ? true : false;
species = "Rare pepe";
}
public Frog(String Name, int Age, double TongueSpeed){
name = Name;
age = Age;
tongueSpeed = TongueSpeed;
isFroglet = (age < 7 & age > 1) ? true : false;
//species = "Rare pepe";
}
public void grow(int addedAge) {
while (age < 12 & addedAge > 0){
age ++;
tongueSpeed ++;
addedAge --;
}
while (age < 30 & addedAge > 0){
age ++;
addedAge --;
}
while (addedAge > 0){
age ++;
tongueSpeed =- 0.5;
addedAge --;
}
isFroglet = (age < 7 & age > 1) ? true : false;
}
public void grow() {
int addedAge = 1;
while (age < 12 & addedAge > 0){
age ++;
tongueSpeed ++;
addedAge --;
}
while (age < 30 & addedAge > 0){
age ++;
addedAge --;
}
while (addedAge > 0){
age ++;
tongueSpeed =- 0.5;
addedAge --;
}
isFroglet = (age < 7 & age > 1) ? true : false;
}
public void eat(Fly fly) {
if (fly.isdead()) {
} else if (tongueSpeed > fly.getSpeed()){
grow();
fly.setMass(0);
} else{
fly.growFly(1);
}
}
public String toString(){
if (isFroglet){
return "My name is " + name + " and I’m a rare froglet! I’m " + age + " months old and my tongue has a speed of " + tongueSpeed + ".";
} else{
return "My name is " + name + " and I’m a rare frog! I’m " + age + " months old and my tongue has a speed of " + tongueSpeed + ".";
}
}
}
Finally, for good measure, class Fly
package flyFrogPond;
public class Fly{
private double mass, speed;
public void setMass( double Mass) { this.mass = Mass;}
public void setSpeed( double Speed) { this.speed = Speed;}
public double getMass() { return mass;}
public double getSpeed() { return speed;}
public Fly(){
mass = 5;
speed = 10;
}
public Fly(double Mass){
mass = Mass;
speed = 10;
}
public Fly(double Mass,double Speed){
mass = Mass;
speed = Speed;
}
public String toString(){
if (mass == 0){
return String.format("I’m dead, but I used to be a fly with a speed of %.2f", speed);
} else{
return String.format("I’m a speedy fly with %.2f and %.2f mass", speed, mass);
}
}
public void growFly(int addedMass){
while (mass < 20 & addedMass > 0){
mass ++;
speed ++;
addedMass --;
}
while (addedMass > 0){
mass ++;
speed =- 0.5;
addedMass --;
}
}
public boolean isdead(){
if (mass == 0){
return true;
} else{
return false;
}
}
}
I tried deleting various variables of Frog, to see if theywere the issue, changing the file location, and adding getters, none worked.
Here is the error message for those of you asking, i compiled and ran it in windows terminal:
PS C:\Users\gurna> javac F:\Notepad++\flyFrogPond\Frog.java
PS C:\Users\gurna> javac F:\Notepad++\flyFrogPond\Pond.java
F:\Notepad++\flyFrogPond\Pond.java:4: error: cannot find symbol
Frog frogPeepo = new Frog("Peepo");
^
symbol: class Frog
location: class Pond
F:\Notepad++\flyFrogPond\Pond.java:4: error: cannot find symbol
Frog frogPeepo = new Frog("Peepo");
^
symbol: class Frog
location: class Pond
2 errors
>Solution :
C:\Users\gurna is not your source root; you must run your compiler in the F:\Notepad++ directory. How else can it know where to look for your other classes?
cd F:\Notepad++
javac flyFrogPond\Frog.java flyFrogPond\Pond.java