Еще прошу помочь разобрать код, не понимаю как код в методе main общается с классом Cat
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 oldFatherName = reader.readLine();
Cat oldFather = new Cat(oldFatherName);
String oldMotherName = reader.readLine();
Cat oldMother = new Cat(oldMotherName);
String fatherName = reader.readLine();
Cat father = new Cat(fatherName);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName);
String sonName = reader.readLine();
Cat son = new Cat(sonName);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName);
System.out.println(oldFather);
System.out.println(oldMother);
System.out.println(father);
System.out.println(catMother);
System.out.println(son);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private Cat parent1;
private Cat parent2;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat parent1, Cat parent2) {
this.name = name;
this.parent1 = parent1;
this.parent2 = parent2;
}
//@Override
public String getName() {
if (parent1 == null && parent2 == null)
return "The cat's name is " + name + ", no mother" + ", no father";
else if (parent1 != null && parent2 != null)
return "The cat's name is " + name + ", mother is " + parent1.name + ", father is " + parent2.name;
if (parent1 == null && parent2 != null)
return "The cat's name is " + name + ", no mother, " + ", father is " + parent2.name;
else if (parent1 != null && parent2 == null)
return "The cat's name is " + name + ", mother is " + parent1.name + ", no father";
}
}
}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 oldFatherName = reader.readLine();
Cat oldFather = new Cat(oldFatherName);
String oldMotherName = reader.readLine();
Cat oldMother = new Cat(oldMotherName);
String fatherName = reader.readLine();
Cat father = new Cat(fatherName);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName);
String sonName = reader.readLine();
Cat son = new Cat(sonName);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName);
System.out.println(oldFather);
System.out.println(oldMother);
System.out.println(father);
System.out.println(catMother);
System.out.println(son);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private Cat parent1;
private Cat parent2;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat parent1, Cat parent2) {
this.name = name;
this.parent1 = parent1;
this.parent2 = parent2;
}
@Override
public String toString() {
if (parent1 == null && parent2 == null)
return "The cat's name is " + name + ", no mother" + ", no father";
else if (parent1 != null && parent2 != null)
return "The cat's name is " + name + parent1.name + parent2.name;
if (parent1 == null && parent2 != null)
return "The cat's name is " + name + ", no mother, " + parent2.name;
else if (parent1 != null && parent2 == null)
return "The cat's name is " + name + parent1.name + ", no father";
}
}
}