Подскажите почему компилятор ошибку выдает ?
Метод toString (missing return statement)
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String grandfatherName = reader.readLine();
Cat grandfather = new Cat(grandfatherName);
String granmotherName= reader.readLine();
Cat grandmother = new Cat(granmotherName);
String fatherName = reader.readLine();
Cat father = new Cat(fatherName,null,grandfather);
String motherName = reader.readLine();
Cat mother = new Cat(motherName,grandmother,null);
String sonName = reader.readLine();
Cat son =new Cat(sonName,mother,father);
String daughterName = reader.readLine();
Cat daughter = new Cat(daughterName,mother,father);
System.out.println(grandfather);
System.out.println(grandmother);
}
public static class Cat {
private String name;
private Cat pmother;
private Cat pfather;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat mother, Cat father) {
this.name = name;
this.pmother = mother;
this.pfather = father;
}
@Override
public String toString() {
if ((pmother == null) & (pfather == null))
return "Cat name is " + name + ", no mother, no father";
else if ((pmother != null)&&(pfather==null))
return "Cat name is " + name + ", mother is " + pmother.name+", no father";
else if ((pmother == null)&&(pfather!=null))
return "Cat name is " + name + ", no mother, father is "+pfather.name;
else if ((pmother != null)&&(pfather!=null))
return "Cat name is " + name + ", mother is " + pmother.name+", father is "+pfather.name;
}
}
}
package com.javarush.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Родственные связи кошек
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String grandfatherName = reader.readLine();
Cat grandfather = new Cat(grandfatherName);
String granmotherName= reader.readLine();
Cat grandmother = new Cat(granmotherName);
String fatherName = reader.readLine();
Cat father = new Cat(fatherName,null,grandfather);
String motherName = reader.readLine();
Cat mother = new Cat(motherName,grandmother,null);
String sonName = reader.readLine();
Cat son =new Cat(sonName,mother,father);
String daughterName = reader.readLine();
Cat daughter = new Cat(daughterName,mother,father);
System.out.println(grandfather);
System.out.println(grandmother);
}
public static class Cat {
private String name;
private Cat pmother;
private Cat pfather;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat mother,Cat father) {
this.name = name;
this.pmother = mother;
this.pfather = father;
}
@Override
public String toString() {
if ((pmother == null)&(pfather==null))
return "Cat name is " + name + ", no mother, no father";
else if ((pmother != null)&&(pfather==null))
return "Cat name is " + name + ", mother is " + pmother.name+", no father";
else if ((pmother == null)&&(pfather!=null))
return "Cat name is " + name + ", no mother, father is "+pfather.name;
else if ((pmother != null)&&(pfather!=null))
return "Cat name is " + name + ", mother is " + pmother.name+", father is "+pfather.name;
}
}
}