"com/codegym/task/task06/task0621/Solution.java:23: error: incompatible types: java.lang.String cannot be converted to com.codegym.task.task06.task0621.Solution.Cat
Cat cat4 = new Cat(catName4, catName2, null);"
I got rid of the "missing return statement issue" (I think), but now I see what's quoted above. Again, any help will be greatly appreciated!
package com.codegym.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Cat relations
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String catName = reader.readLine(); //grandpa
Cat cat = new Cat(catName, null, null);
String catName2 = reader.readLine(); //grandma
Cat cat2 = new Cat(catName, null, null);
String catName3 = reader.readLine(); // father
Cat cat3 = new Cat(catName, null, cat);
String catName4 = reader.readLine(); //mother
Cat cat4 = new Cat(catName, cat2, null);
String catName5 = reader.readLine(); //son
Cat cat5 = new Cat(catName, cat4, cat3);
String catName6 = reader.readLine(); //daughter
Cat cat6 = new Cat(catName, cat4, cat3);
System.out.println(cat.toString());
System.out.println(cat2.toString());
System.out.println(cat3.toString());
System.out.println(cat4.toString());
System.out.println(cat5.toString());
System.out.println(cat6.toString());
}
public static class Cat {
private String name;
private Cat mother;
private Cat father;
Cat(String name, Cat mother, Cat father) {
this.name = name;
this.mother = mother;
this.father = father;
}
@Override
public String toString() {
if (this.mother == null && this.father == null) {
return "The cat's name is " + name + ", no mother, no father";
}
if (this.mother != null && this.father == null) {
return "The cat's name is " + name + ", " + mother.name + " is the mother, no father";
}
if (this.father != null && this.mother == null) {
return "The cat's name is " + name + ", no mother " + father.name + " is the father";
}
if (this.father != null && this.mother != null) {
return "The cat's name is " + name + ", " + mother.name + " is the mother, " + father.name + " is the father";
}
}
}
}