我应该创建一个接受字符和对象的方法。

huangapple 未分类评论59阅读模式
英文:

I should create a method that accepts a character and object

问题

这里我应该创建一个方法,该方法将接受一个字符和一个对象作为参数,然后将参数设置为正确的属性。

public class Person {
    private String id;
    private char gender;
    private int yob;
    private char status;
    private Person parent;

    public Person(char gender, int yob)
    {
        this.gender = gender;
        this.yob = yob;
    }
    public void setParent(char P, Person parent)
    {
        this.parent = parent;
    }
}

所以我认为他们希望我设置父母是 'M' 代表母亲或 'F' 代表父亲。我不确定如何在这个方法中添加这些参数来完成这个任务。有人可以告诉我我应该在这里做什么吗?

英文:

So I should create this method that will accept a character and an object as a parameter. Then set the correct attribute to the parameter.

public class Person {
    private String id;
    private char gender;
    private int yob;
    private char status;
    private Person parent;

    public Person(char gender, int yob)
    {
        this.gender = gender;
        this.yob = yob;
    }
    public void setParent(char P,Person parent)
    {
        this.parent = ();
    }
}

So I think they want me to set whether the parent is a 'M' for Mother or 'F' for Father. I am not sure how I am suppose to add these parameters to complete this method to accomplish that. Can anyone tell me what I would do right here?

答案1

得分: -1

以下是翻译好的部分:

听起来你的任务是要创建一个构造函数,而不是一个方法。

public void Person(char gender, Person parent) {
    this.gender = gender;
    this.parent = parent;
}
英文:

What it sounds like is that your assignment wants you to create a constructor, not a method.

public void Person(char gender, Person parent) {
    this.gender = gender;
    this.parent = parent;
}

huangapple
  • 本文由 发表于 2020年3月15日 08:23:39
  • 转载请务必保留本文链接:https://java.coder-hub.com/60688623.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定