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));
//for(int i=0;i<6;i++){
String grandFatherName = reader.readLine();
Cat grandFather = new Cat(grandFatherName);
String grandMotherName = reader.readLine();
Cat grandMother = new Cat(grandMotherName);
String fatherName = reader.readLine();
Cat father = new Cat(fatherName, null, grandFather);
String motherName = reader.readLine();
Cat mother = new Cat(motherName, grandMother, null);
String sonName = reader.readLine();
Cat son = new Cat(sonName, mother, father);
String daughterName = reader.readLine();
Cat daughter = new Cat(daughterName, mother, father);
System.out.println(grandFather);
System.out.println(grandMother);
System.out.println(father);
System.out.println(mother);
System.out.println(son);
System.out.println(daughter);
//}
}
public static class Cat {
private String name;
private Cat father;
private Cat mother;
Cat(String name) {
this.name = name;
}
/*Cat(String name, Cat parent) {
this.name = name;
this.parent = parent.name;
}*/
Cat(String name, Cat mom, Cat dad){
this.name = name;
this.mother = mom.name;
this.father = dad.name;
}
@Override
public String toString() {
if (mother==null && father==null)
return "The cat's name is " + this.name +", no mother, no father";
else if (mother==null)
return "The cat's name is " + this.name + ", no mother, " + father.name + " is the father";
else if (father==null)
return "The cat's name is " + this.name + ", " + mother.name + " is the mother, no father";
else
return "The cat's name is " + this.name + ", " + mother.name + " is the mother, " + father.name + " is the father";
}
}
}
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 motherName = reader.readLine();
Cat catMother = new Cat(motherName);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catMother);
System.out.println(catMother);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private Cat parent;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat parent) {
this.name = name;
this.parent = parent;
}
@Override
public String toString() {
if (parent == null)
return "The cat's name is " + name + ", no mother ";
else
return "The cat's name is " + name + ", " + parent.name + " is the mother";
}
}
}