Skip to content
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

Создана база семейного древа. #16

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/ru/gb/family_tree/FamilyTree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ru.gb.family_tree;

import java.util.ArrayList;
import java.util.List;

public class FamilyTree {
private List<Human> humanList;

public FamilyTree() {
humanList = new ArrayList<>();
}

public void addHuman(Human human){
humanList.add(human);
}

public Human findByName(String nameHuman){
for(Human human: humanList){
if(human.getName().equalsIgnoreCase(nameHuman)){
return human;
}
}
return null;
}

@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Список людей:\n");
for (Human human : humanList) {
stringBuilder.append(human);
stringBuilder.append("\n");
}
return stringBuilder.toString();
}
}
5 changes: 5 additions & 0 deletions src/ru/gb/family_tree/Gender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.gb.family_tree;

public enum Gender {
Male, Female
}
35 changes: 35 additions & 0 deletions src/ru/gb/family_tree/Human.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ru.gb.family_tree;

import java.time.LocalDate;
import java.util.List;

public class Human {
private String name;
private LocalDate dob, dod;
private List<Human> children;
private Human father, mather;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ни в какой момент не изменяется состояние этих полей

private Gender gender;

public Human(String name, Gender gender, LocalDate dob) {
this.name = name;
this.gender = gender;
this.dob = dob;
}

public Human(String name, Gender gender) {
this(name, gender, LocalDate.of(1900,12,12));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему вдруг именно такая дата? Ошибка писать такие даты, потом непонятно откуда берутся артефакты)

}

public String getName() {
return name;
}

public Gender getGender() {
return gender;
}

@Override
public String toString() {
return "Name: " + name + ", Gender: " + gender + ", Birthday: " + dob;
}
}
26 changes: 26 additions & 0 deletions src/ru/gb/family_tree/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.gb.family_tree;

import java.time.LocalDate;

public class Main {
public static void main(String[] args) {
FamilyTree familyTree = new FamilyTree();

Human human1 = new Human("Oleg", Gender.Male, LocalDate.of(1985, 12, 12));
Human human2 = new Human("Olga", Gender.Female, LocalDate.of(1984, 6, 18));
Human human3 = new Human("Ruslan", Gender.Male, LocalDate.of(2006, 10, 10));
Human human4 = new Human("Lena", Gender.Female, LocalDate.of(2016, 5, 4));
Human human5 = new Human("Polina", Gender.Female);

familyTree.addHuman(human1);
familyTree.addHuman(human2);
familyTree.addHuman(human3);
familyTree.addHuman(human4);
familyTree.addHuman(human5);

System.out.println(familyTree);

System.out.println(familyTree.findByName("olga").getName());

}
}
2 changes: 2 additions & 0 deletions src/ru/gb/vending_machine/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ public static void main(String[] args) {

Product product1 = new Bottle("coca-cola", 150, 1.5);
Product product2 = new Product("milko", 100);
Product product3 = new Product("twix", 65);

vendingMachine.addProduct(product1);
vendingMachine.addProduct(product2);
vendingMachine.addProduct(product3);

System.out.println(vendingMachine.getProductsInfo());
}
Expand Down