So, this is the sample code that we are supposed to use as reference for a formative assessment. I decided to run it in the terminal to see if it would work, and it always result in "Error Cannot Find Symbol". Would appreciate if someone could tell me how to fix it.
Here's the error message:
/Testing.java:6: error: cannot find symbol
Person p1 = new Person();
^
symbol: class Person
location: class Testing
/Testing.java:6: error: cannot find symbol
Person p1 = new Person();
^
symbol: class Person
location: class Testing
/Testing.java:7: error: cannot find symbol
Person p3 = new Person("Chris", 30);
^
symbol: class Person
location: class Testing
/Testing.java:7: error: cannot find symbol
Person p3 = new Person("Chris", 30);
^
symbol: class Person
location: class Testing
/Testing.java:10: error: cannot find symbol
Person p2;
^
symbol: class Person
location: class Testing
/Testing.java:12: error: cannot find symbol
p2 = new Person();
^
symbol: class Person
location: class Testing
6 errors
And here's the code:
public class Testing{
public static void main(String [] args){
//declare and instantiate;
Person p1 = new Person();
Person p3 = new Person("Chris", 30);
//declare
Person p2;
//instantiate;
p2 = new Person();
//Assign values for p1 and p2
/*
p1.name="Lawrence";
p2.name="Percy";
p1.age=20;
p2.age=-5;
*/
p1.setName("Lawrence");
p2.setName("Percy");
p1.setAge(20);
p2.setAge(-5);
//Display values
//System.out.println(p1.name + " at age " + p1.age);
//System.out.println(p2.name + " at age " + p2.age);
p1.showDetails();
p2.showDetails();
System.out.println(p3.getName() + " at age " + p3.getAge());
}
}
Edit: People asked for the person class as well, so I'm putting it here:
public class Person{
//variables
private String name;
private int age;
//constructor
public Person(){
//nothing here...
}
public Person(String name, int age){
setName(name);
setAge(age);
}
//methods
public void showDetails(){
System.out.println(name + " at age " + age);
}
//Setters
public void setName(String name){
this.name=name;
}
public void setAge(int age){
if(age>0)
this.age=age;
else
this.age=0;
}
//Getters
public String getName(){
return name;
}
public int getAge(){
return age;
}
}
class A{
}