我的方法来自另一个 class,不会在我的 Main class 中调用输入

My method from another class, will not call an input in my Main class

我正在自学 Java,我正在尝试 运行 我编写的一段代码。在我的 Udemy 自学课程中,我正在讨论 classes。我在我的 IDE IntelliJ 中做了一个项目,叫做 Person。本质上,目标是输入一个字符串形式的名字和姓氏,以及一个数字形式的年龄,然后 运行 通过并吐出该人的全名,如果他们是青少年。

然而,我正处于输入阶段,并且在我的 Main Class 中不断收到一条错误消息。然而,当我尝试输入 Dan 时,(person.SetFirstName("Dan")),它返回一个错误提示,"setFirstName() in person cannot be applied to java.lang.String"

下面是我的主要代码class,以及我个人的前几行代码class,我觉得如果我能用第一种方法找出问题所在,我可以解决其余的问题。

我在我的 class 论坛上问过,但我似乎得不到答案,有些人认为这可能是我的 IDE 本身的问题?

public class 主 {

public static void main(String[] args) {

Person person = new Person();
person.setFirstName("Dan");
person.setLastName();
person.setAge();
    System.out.println("Full Name = " + person.getFullName());
    System.out.println("Are they a teenager? " + person.isTeen());
    person.setFirstName();
    person.setAge();
    System.out.println("Full Name = " + person.getFullName());
    System.out.println("Are they a teenager? " +person.isTeen());
    person.setLastName();
    System.out.println("Full Name = " + person.getFullName());

}

}

public class 人 {

private String firstName;
private String lastName;
private int age;

public String getFirstName(){
    return this.firstName;
}
public void setFirstName(){
    this.firstName = firstName;
}

改变这个

public void setFirstName(){
    this.firstName = firstName;
}

public String setFirstName(){
    this.firstName = firstName;
    return firstName;
}

public void setFirstName() 没有定义任何参数,但您将字符串参数传递给它 (person.setFirstName("Dan");) - 因此是错误。

尝试将方法签名更改为:

public void setFirstName(String firstName){
        this.firstName = firstName;
    }