ΠΡΠΈ Π·Π°ΠΏΡΡΠΊΠ΅ Π² ΠΌΠΎΡΠΌ ΠΊΠΎΠΌΠΏΠΈΠ»ΡΡΠΎΡΠ΅ ΠΏΡΠΎΡΡΠΎ Π½Π΅ Π·Π°ΠΏΡΡΠΊΠ°Π΅ΡΡΡ. Π’ΡΡ Π½Π° ΡΠ°ΠΉΡΠ΅ Π²ΡΠ΄Π°ΡΡ ΡΠ»Π΅Π΄ΡΡΡΡΡ ΠΎΡΠΈΠ±ΠΊΡ:
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Cats' relations
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Cats' relations
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String grandpaName = reader.readLine();
Cat catGrandpa = new Cat(grandpaName);
String grandmaName = reader.readLine();
Cat catGrandma = new Cat(grandmaName);
String dadName = reader.readLine();
Cat catDad = new Cat (dadName, null, catGrandpa);
String momName = reader.readLine();
Cat catMom = new Cat (momName, catGrandma, null);
String sonName = reader.readLine();
Cat catSon = new Cat (sonName, catMom, catDad);
String daughterName = reader.readLine();
Cat catDaughter = new Cat (daughterName, catMom, catDad);
System.out.println(catGrandpa);
System.out.println(catGrandma);
System.out.println(catDad);
System.out.println(catMom);
System.out.println(catSon);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
// private boolean gender;
private Cat mother;
private Cat father;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat mother, Cat father) {
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, father is " + father.name;
else if (mother != null && 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 + ", mother is " + mother.name + "father is " + father.name;
else
return "The cat's name is " + name + ", no mother, no father";
}
}
}