Public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String motherName = reader.readLine();
Cat catMother = new Cat(motherName);
String fatherName = reader.readLine();
Cat catFather = new Cat(fatherName);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catMother, catFather);
String gfatherName = reader.readLine();
Cat catGfather = new Cat(gfatherName, catFather);
String gmotherName = reader.readLine();
Cat catGmother = new Cat(gmotherName);
String sonName = reader.readLine();
Cat catSon = new Cat(sonName, catMother, catFather);
System.out.println(catMother);
System.out.println(catFather);
System.out.println(catDaughter);
System.out.println(catGfather);
System.out.println(catGmother);
System.out.println(catSon);
}
public static class Cat {
private String name;
private Cat mother;
private Cat father;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat mother) {
this.name = name;
this.mother = mother;
}
n Вот с этого места ругается
Cat(String name, Cat father) {
this.name = name;
this.father = father;
}
Cat(String name, Cat mother, Cat father) {
this.name = name;
this.mother = mother;
this.father = father;
}
@Override
public String toString() {
if (mother == null)
return "The cat's name is " + name + ", no mother " + ", father is " + father.name;
else if (father == null)
return "The cat's name is " + name + ", mother is " + mother.name + ", no father";
//else if (mother == null && father == null)
//return "The cat's name is " + name + "no mother, no father";
else
return "The cat's name is " + name + ", mother is " + mother.name + ", father is" + father.name;
}
}
}
Александр
11 уровень
ругается на конструктор? не могу понять что не так
Обсуждается
Комментарии (1)
- популярные
- новые
- старые
Для того, чтобы оставить комментарий Вы должны авторизоваться
НикитаExpert
2 ноября 2020, 16:13полезный
Cat(String name, Cat mother) {
this.name = name;
this.mother = mother;
}
n Вот с этого места ругается
Cat(String name, Cat father) {
this.name = name;
this.father = father;
У вас два идентичных коструктора. Как программа поймет какой нужно использовать, как вы введете данные?
+3