Выдает ответ:
Имя: null, пол: женский, возраст: 0
Имя: null, пол: женский, возраст: 0
Имя: null, пол: женский, возраст: 0
Имя: null, пол: женский, возраст: 0
Имя: null, пол: женский, возраст: 0
Имя: null, пол: женский, возраст: 0
Имя: null, пол: женский, возраст: 0
Имя: null, пол: женский, возраст: 0
Имя: null, пол: женский, возраст: 0
почему в метод toString() не передаются данные.
Хотя вставляю все данные в IDEA, все срабатывает,
если открыть четез плагин в IDEA, не срабатывает
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
public class Solution {
public static void main(String[] args) {
Human father = new Human ("Павел", true, 25);
Human mother = new Human ("Аня", false, 28);
Human father2 = new Human ("faцйуейцуеdg", true, 245);
Human mother2 = new Human ("faqweqTйцуейцеRdg", false, 238);
Human f1 = new Human ("fad123123g", true, 2, father, mother);
Human f2 = new Human ("f1241adg", true, 5, father, mother2);
Human f3 = new Human ("fa325dg", true, 17, father2, mother);
Human m1 = new Human ("faqweqTRdg", false, 28, father2, mother2);
Human m2 = new Human ("faqweqTg", false, 28, father, mother2);
System.out.println(father);
System.out.println(mother);
System.out.println(father2);
System.out.println(mother2);
System.out.println(f1);
System.out.println(f2);
System.out.println(f3);
System.out.println(m1);
System.out.println(m2);
}
public static class Human {
String name;
boolean sex;
int age;
Human father;
Human mother;
public Human (String name, boolean sex, int age){
name = this.name;
sex = this.sex;
age = this.age;
}
public Human (String name, boolean sex, int age, Human father, Human mother){
name = this.name;
sex = this.sex;
age = this.age;
father = this.father;
mother = this.mother;
}
public String toString() {
String text = "";
text += "Имя: " + this.name;
text += ", пол: " + (this.sex ? "мужской" : "женский");
text += ", возраст: " + this.age;
if (this.father != null)
text += ", отец: " + this.father.name;
if (this.mother != null)
text += ", мать: " + this.mother.name;
return text;
}
}
}