[解决] - 谢谢大家!明白了!
我在第8行收到错误:“在JavaBeans中找不到符号”。
我也在第16行找到一个无法找到变量SetAge,而JCreator在这一行中也有一个问题:“运算符+不能应用于Person.getAge.int”。
我想我可能做错了包或导致我的主类文件没有看到我的其他类文件的东西。有人可以帮忙吗?谢谢! (抱歉凌乱的帖子)
包persontestdebug;
公共类PersonTestDebug {
public static void main( String args[] ){
Person person1 = Person( "Susan", "Beal", 19 );
System.out.printf( "Created %s %s, age %d\n", person1.getFirstName(), person1.getLastName(), person1.getAge() );
System.out.println( person1.getFirstName()+" is" +person1.getAge()+" years old.");
System.out.printf( "Happy Birthday to %s %s\n", person1.getFirstName(), person1.getLastName() );
person1.setAge = person1.getAge() + 1;
System.out.println( "This person is now "+person1.getAge()+" years old.");
} // end main
} //结束类PersonTestDebug
--------------和另一个班级:
包persontestdebug;
公共类人员{
private String firstName;
private String lastName;
private int age;
private int years;
public void Person( String first, String last, int years ){
firstName = first;
lastName = last;
if ( years > 0 ){
age = years;
}
} // end Person constructor
public String getFirstName(){
return firstName;
} // end method getFirstName
public void setFirstName( String first ){
firstName = first;
} // end method setFirstName
public String getLastName(){
return lastName;
} // end method getLastName
public void setLastName( String last ){
lastName = last;
} // end method setLastName
public int getAge(){
return age;
} // end method getAge
public void setAge( int years ){
if ( years > 0 ){
age = years;
}
} // end method setAge
} //结束类人
答案 0 :(得分:1)
Person person1 = Person( "Susan", "Beal", 19 );
应为Person person1 = new Person( "Susan", "Beal", 19 );
答案 1 :(得分:-1)
public void Person(String first,String last,int years)应该 public Person(String first,String last,int years)