public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
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);
String motherName = reader.readLine();
Cat Mother = new Cat(motherName);
String sonName = reader.readLine();
Cat Son = new Cat(sonName);
String daughterName = reader.readLine();
Cat Daughter = new Cat(daughterName);
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 parent1;
private Cat parent2;
Cat(String name) {
this.name = name;
}
Cat ( String name, Cat parent1){
this.name = name;
this.parent1 = parent1;
}
Cat(String name, Cat parent1, Cat parent2) {
this.name = name;
this.parent1 = parent1;
this.parent2 = parent2;
}
@Override
public String toString() {
if (parent1 == null)
return "The cat's name is " + name + ", no mother, "+" no father";
else
return "The cat's name is " + name + ", "+"no mother, "+ parent2 +" is the father" ;
}
public String toString2(){
if ( parent2 == null)
return "The cat's name is " + name + ", no mother, "+" no father";
else
return "The cat's name is " + name + ", " + parent1 + " is the mother " + "no 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 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);
String motherName = reader.readLine();
Cat Mother = new Cat(motherName);
String sonName = reader.readLine();
Cat Son = new Cat(sonName);
String daughterName = reader.readLine();
Cat Daughter = new Cat(daughterName);
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 parent1;
private Cat parent2;
Cat(String name) {
this.name = name;
}
Cat ( String name, Cat parent1){
this.name = name;
this.parent1 = parent1;
}
Cat(String name, Cat parent1, Cat parent2) {
this.name = name;
this.parent1 = parent1;
this.parent2 = parent2;
}
@Override
public String toString() {
if (parent1 == null)
return "The cat's name is " + name + ", no mother, "+" no father";
else
return "The cat's name is " + name + ", "+"no mother, "+ parent2 +" is the father" ;
}
public String toString2(){
if ( parent2 == null)
return "The cat's name is " + name + ", no mother, "+" no father";
else
return "The cat's name is " + name + ", " + parent1 + " is the mother " + "no father";
}
}
}