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 grandvatherName = reader.readLine();
Cat catGrandVather = new Cat(grandvatherName);
String grandmotherName = reader.readLine();
Cat catGrandMother = new Cat(grandmotherName);
String vatherName = reader.readLine();
Cat catVather = new Cat(vatherName, catGrandVather,null);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName, null,catGrandMother);
String sonName = reader.readLine();
Cat catSon = new Cat(sonName, catVather, catMother);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catVather, catMother);
System.out.println(catGrandVather);
System.out.println(catGrandMother);
System.out.println(catVather);
System.out.println(catMother);
System.out.println(catSon);
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(parent2 == null)
return "The cat's name is " + name + ", no mother, " + "father is " + parent1.name;
else
if(parent1 == null)
return "The cat's name is " + name + ", mother is " + parent2.name + ", no vather";
else
return "The cat's name is " + name + ", mother is " + parent2.name + ", vather is " + parent1.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 grandvatherName = reader.readLine();
Cat catGrandVather = new Cat(grandvatherName);
String grandmotherName = reader.readLine();
Cat catGrandMother = new Cat(grandmotherName);
String vatherName = reader.readLine();
Cat catVather = new Cat(vatherName, catGrandVather,null);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName, null,catGrandMother);
String sonName = reader.readLine();
Cat catSon = new Cat(sonName, catVather, catMother);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catVather, catMother);
System.out.println(catGrandVather);
System.out.println(catGrandMother);
System.out.println(catVather);
System.out.println(catMother);
System.out.println(catSon);
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(parent2 == null)
return "The cat's name is " + name + ", no mother, " + "father is " + parent1.name;
else
if(parent1 == null)
return "The cat's name is " + name + ", mother is " + parent2.name + ", no vather";
else
return "The cat's name is " + name + ", mother is " + parent2.name + ", vather is " + parent1.name;
}
}
}