Как прописать в конструктор объекта поле sex? Валидатор ругается: Невозможно привести объект типа "java.lang.String" к типу "boolean".
Так же не понятно как прописывать father и mother. Что это за тип переменных и как их прописывать объекту?
package com.javarush.task.jdk13.task07.task0724;
/*
Семья
*/
public class Solution {
public static void main(String[] args) {
// напишите тут ваш код
Human pavel = new Human("Pavel", "мужской", 45);
//Human igor = new Human("Igor", "мужской", 49);
//Human andrey = new Human("Andrey", "мужской", 23);
//Human anna = new Human("Anna", "женский", 31);
//Human vadim = new Human("Vadim", "мужской", 40, );
}
public static class Human {
// напишите тут ваш код
String name;
boolean sex;
int age;
Human father;
Human mother;
public Human(String name, boolean sex, int age){
this.name = name;
this.sex = sex;
this.age = age;
}
public Human(String name, boolean sex, int age, Human father, Human mother){
this.name = name;
this.sex = sex;
this.age = age;
this.father = father;
this.mother = 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;
}
}
}