-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Первый проект! #22
base: master
Are you sure you want to change the base?
Первый проект! #22
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>FamilyTree</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ru.GeekBrains.Voronyuk00.FamilyTree; | ||
|
||
public class App { | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
Human person1 = new Human("Анна", "Воронюк",1971,7,29,Gender.female); | ||
Human person2 = new Human("Евгений","Воронюк",1967,5,9,Gender.male); | ||
Human person3 = new Human("Алексей","Воронюк",2000,4,12,Gender.male); | ||
Human person4 = new Human("Марина", "Воронюк",2000,10,5,Gender.female); | ||
Human person5 = new Human("Галина","Агафонова", 1940,8,14,2017,9,11,Gender.female); | ||
|
||
// Создание семейного дерева | ||
FamilyTree familyList = new FamilyTree(); | ||
familyList.addPerson(person1); | ||
familyList.addPerson(person2); | ||
familyList.addPerson(person3); | ||
familyList.addPerson(person4); | ||
familyList.addPerson(person5); | ||
|
||
person1.addChild(person3); | ||
person1.addChild(person4); | ||
person2.addChild(person3); | ||
person2.addChild(person4); | ||
|
||
person3.addFather(person1); | ||
person3.addMother(person2); | ||
person4.addFather(person1); | ||
person4.addMother(person2); | ||
person1.addMother(person5); | ||
|
||
System.out.println(person5 + " Возраст " + person5.getAge()); | ||
|
||
person5.addChild(person1); | ||
person5.showChildren(); | ||
|
||
familyList.searchPerson("Алексей","Воронюк"); | ||
familyList.searchPerson("Иван","Высоцкий"); | ||
|
||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package ru.GeekBrains.Voronyuk00.FamilyTree; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
/** | ||
* Класс для создания семейного дерева | ||
*/ | ||
public class FamilyTree { | ||
|
||
private List<Human> familyList; | ||
/** | ||
* Конструктор для создания семейного дерева | ||
*/ | ||
public FamilyTree(){ | ||
familyList = new ArrayList<>(); | ||
} | ||
|
||
public void addPerson(Human h) { | ||
familyList.add(h); | ||
} | ||
/** | ||
* | ||
* @param name имя человека | ||
* @param surname фамилия человека | ||
* @return информация о человеке | ||
*/ | ||
public void searchPerson(String name, String surname) { | ||
boolean hasPerson = false; | ||
for(Human h : familyList) { | ||
if(h.getName().equalsIgnoreCase(name) && h.getSurname().equalsIgnoreCase(surname)) { | ||
System.out.println(h); | ||
hasPerson = true; | ||
} | ||
} | ||
if(!hasPerson) { | ||
System.out.print("Такого человека нет"); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ru.GeekBrains.Voronyuk00.FamilyTree; | ||
|
||
public enum Gender { | ||
male,female; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package ru.GeekBrains.Voronyuk00.FamilyTree; | ||
|
||
import java.time.LocalDate; | ||
import java.time.Period; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
/** | ||
* Класс для создания человека | ||
*/ | ||
public class Human { | ||
|
||
private String name; | ||
private String surname; | ||
private LocalDate dob, dod; | ||
Gender gender; | ||
List<Human> children; | ||
Human father, mother; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private |
||
/** | ||
* Конструктор для создания человека | ||
* @param name - имя человека | ||
* @param surname - фамилия человека | ||
* @param year - год рождения человека | ||
* @param month - месяц рождения человека | ||
* @param day - день рождения человека | ||
* @param gender - пол человека | ||
*/ | ||
Human(String name, String surname, int year, int month,int day,Gender gender){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public |
||
this.name = name; | ||
this.surname = surname; | ||
this.dob = LocalDate.of(year, month, day); | ||
this.gender = gender; | ||
children = new ArrayList<>(); | ||
} | ||
/** | ||
* Конструктор для создания человека | ||
* @param name - имя человека | ||
* @param surname - фамилия человека | ||
* @param year - год рождения человека | ||
* @param month - месяц рождения человека | ||
* @param day - день рождения человека | ||
@param year2 - год смерти человека | ||
* @param month2 - месяц смерти человека | ||
* @param day2 - день смерти человека | ||
* @param gender - пол человека | ||
*/ | ||
Human(String name, String surname, int year, int month,int day,int year2, int month2, int day2,Gender gender){ | ||
this.name = name; | ||
this.surname = surname; | ||
this.dob = LocalDate.of(year, month, day); | ||
this.dod = LocalDate.of(year2, month2, day2); | ||
this.gender = gender; | ||
children = new ArrayList<>(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. нарушение принципа DRY |
||
|
||
/** | ||
* Метод для получения имени | ||
* @return имя | ||
*/ | ||
public String getName() { | ||
return this.name; | ||
} | ||
/** | ||
* Метод для получения фамилии | ||
* @return фамилия | ||
*/ | ||
public String getSurname() { | ||
return this.surname; | ||
} | ||
|
||
/** | ||
* Добавление матери человека | ||
* @param h - мать человека | ||
*/ | ||
public void addMother(Human h) { | ||
this.mother = h; | ||
} | ||
/** | ||
* Добавление отца человека | ||
* @param h - отец человека | ||
*/ | ||
public void addFather(Human h) { | ||
this.father = h; | ||
} | ||
/** | ||
* Метод для вывода матери человека | ||
* @return мать человека | ||
*/ | ||
public Human showMother() { | ||
return this.mother; | ||
} | ||
/** | ||
* Метод для вывода отца человека | ||
* @return отец человека | ||
*/ | ||
public Human showFather() { | ||
return this.mother; | ||
} | ||
/** | ||
* Метод для получения возраста | ||
* @return возраст | ||
*/ | ||
public int getAge() { | ||
if(dod == null) { | ||
return Period.between(this.dob, LocalDate.now()).getYears(); | ||
} | ||
else { | ||
return Period.between(dob, dod).getYears(); | ||
} | ||
} | ||
|
||
public Gender getGender() { | ||
return this.gender; | ||
} | ||
|
||
/** | ||
* Метод для добавления ребенка | ||
* @param child - добавляемый ребёнок | ||
*/ | ||
public void addChild(Human child) { | ||
children.add(child); | ||
} | ||
/** | ||
* Метод для демонстрации детей | ||
*/ | ||
public void showChildren() { | ||
boolean hasChildren = false; | ||
for(Human h : children) { | ||
System.out.println(h); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Возвращаем результат |
||
hasChildren = true; | ||
} | ||
|
||
if(!hasChildren) { | ||
System.out.println("Нет детей"); | ||
} | ||
} | ||
@Override | ||
public String toString() { | ||
return "Имя = " + name + ", фамилия = " + surname + ", дата рождения = " + dob + ", пол = " + gender ; | ||
} | ||
|
||
|
||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Старайтесь писать методы, которые возвращают результат своей работы, а не выводят в консоль