PS: i know it's a complicated way to get the job done, but i didn't want to system print 80 billion times
package com.codegym.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
/*
Cat relations
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Cat> cats = new ArrayList<Cat>();
for (int i = 0; i < 2; i++) {
String name = reader.readLine();
Cat cat = new Cat(name);
cats.add(cat);
}
for (int i = 0; i < 2; i++) {
String name = reader.readLine();
if (i==1) {
Cat cat = new Cat(name, null, cats.get(i));
cats.add(cat);
break;
}
Cat cat = new Cat(name, cats.get(i));
cats.add(cat);
}
for (int i = 2; i < 4; i++) {
String name = reader.readLine();
Cat cat = new Cat(name, cats.get(2),cats.get(3));
cats.add(cat);
}
int cattos = cats.size();
for (int i = 0; i < cattos; i++) {
System.out.println(cats.get(i));
}
}
public static class Cat {
private String name;
private Cat father;
private Cat mother;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat father) {
this.name = name;
this.father = father;
}
Cat(String name, Cat father, Cat mother){
this.name = name;
this.mother = mother;
this.father = father;
}
@Override
public String toString() {
if (mother == null & father == null)
return "The cat's name is " + name + ", no mother, no father ";
else if (mother != null & father == null)
return "The cat's name is " + name + ", " + mother.name + " is the mother, no father";
else if (mother == null & father != null)
return "The cat's name is " + name + ", no mother, " + father.name + " is the father";
else
return "The cat's name is " + name + ", " + mother.name + " is the mother, " + father.name + " is the father";
}
}
}