package pl.codegym.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Relacje między kotami
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String imieDziadka = reader.readLine();
Kot kotDziadek = new Kot(imieDziadka);
String imieBabci = reader.readLine();
Kot kotBabcia = new Kot(imieBabci);
String imieOjca = reader.readLine();
Kot kotOjciec = new Kot(imieOjca, kotDziadek);
String imieMatki = reader.readLine();
Kot kotMatka = new Kot(imieMatki, kotBabcia);
String imieSyna = reader.readLine();
Kot kotSyn = new Kot(imieSyna, kotOjciec, kotMatka);
String imieCorki = reader.readLine();
Kot kotCorka = new Kot(imieCorki, kotOjciec, kotMatka);
System.out.println(kotDziadek);
System.out.println(kotBabcia);
System.out.println(kotOjciec);
System.out.println(kotMatka);
System.out.println(kotSyn);
System.out.println(kotCorka);
}
public static class Kot {
private String imie;
private Kot ojciec;
private Kot matka;
Kot(String imie) {
this.imie = imie;
}
Kot(String imie, Kot rodzic) {
this.imie = imie;
}
Kot(String imie, Kot ojciec, Kot matka) {
this.imie = imie;
this.ojciec = ojciec;
this.matka = matka;
}
@Override
public String toString() {
if (matka == null && ojciec == null)
return "Imię kota to " + imie + ", brak matki, brak ojca";
else if (matka == null && ojciec != null)
return "Imię kota to " + imie + ", brak matki, " + ojciec.imie + " to ojciec";
else if (matka != null && ojciec == null)
return "Imię kota to " + imie + ", matka to " + matka.imie + ", brak ojca";
else
return "Imię kota to " + imie + ", matka to " + matka.imie + ", ojciec to " + ojciec.imie;
}
}
}
Proszę o pomoc z zadaniem...
Dyskutowane
Komentarze (2)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Jake BB
11 marca 2020, 13:22
Ok thank you very much for your help, I get it now ;)
0
Guadalupe Gagnon
9 marca 2020, 14:26
#1 Lines 66 and 70 have different outputs for the father. I don't speak or write in polish but " to ojciec" precedes the father name on line 70, but on line 60 " to ojciec" is after the the father.
#2 the father and mother objects, lines 21 and 24, do not have their parent set properly. You pass the correct parent into the constructor, but the constructor does not does not set the value of the parent. Because passing in one parent does not help the compiler understand if that is a father or a mother you will have to figure out a different way of doing this. Suggestions: use the constructor that passes in two parents in which case you will have to figure out what to pass in when there is no mother or no father; or you could pass in a boolean value (true/false) to tag the passed in parent as either mother or father.
+1