SlideShare a Scribd company logo
s
Family Tree in Java
This program is finding its parent grandparent and siblings. There are
methods to find the grandchildren, most similar descendant, etc.
import java.util.ArrayList;
import java.util.List;
public class FamilyTree {
Tree t;
public FamilyTree(Tree t) {
this.t = t;
}
public String getParent(Node person) {
if (person.getParent() == null)
return "No parent";
return (String) person.getParent().getElement();
}
public String getGrandparent(Node person) {
if (person.getParent() == null
|| person.getParent().getParent() == null)
return "No grandparent";
return (String) person.getParent().getParent().getElement();
}
public List<String> getChildren(Node person) {
List<String> children = new ArrayList<String>();
for (Node child : person.getChildren()) {
children.add((String) child.getElement());
}
return children;
}
public List<String> getGrandchildren(Node person) {
List<String> grandchildren = new ArrayList<String>();
for (Node child : person.getChildren()) {
grandchildren.addAll(getChildren(child));
}
return grandchildren;
}
public List<String> getSiblings(Node person) {
List<String> siblings = new ArrayList<String>();
if (person.getParent() == null)
return siblings;
for (Node sibling : person.getParent().getChildren()) {
if (sibling != person)
siblings.add((String) sibling.getElement());
}
return siblings;
}
public int getSimilarityScore(String a, String b) {
int score = 0;
int minLength = Math.min(a.length(), b.length());
for (int i = 0; i < minLength; i++) {
if (a.charAt(i) == b.charAt(i))
score++;
else
break;
}
return score;
}
public String mostSimilarDescendant(Node person) {
if (person.getChildren().isEmpty())
return null;
String mostSimilar = null;
int mostSimilarScore = -1;
for (String child : getChildren(person)) {
int score = getSimilarityScore((String)
person.getElement(), child);
if (score > mostSimilarScore) {
mostSimilar = child;
mostSimilarScore = score;
}
}
for (String grandchild : getGrandchildren(person)) {
int score = getSimilarityScore((String)
person.getElement(), grandchild);
if (score > mostSimilarScore) {
mostSimilar = grandchild;
mostSimilarScore = score;
}
}
return mostSimilar;
}
}

More Related Content

What's hot

Sistema de arquivos
Sistema de arquivosSistema de arquivos
Sistema de arquivos
Virgínia
 
Conectividade em grafos
Conectividade em grafosConectividade em grafos
Conectividade em grafos
Michelle Guerreiro C Silva
 
Soa cap2 exercicios resolvidos shell
Soa cap2 exercicios resolvidos shellSoa cap2 exercicios resolvidos shell
Soa cap2 exercicios resolvidos shell
portal_Do_estudante
 
Estrutura de Dados - Aula 03 - Ponteiros e Funções
Estrutura de Dados - Aula 03 - Ponteiros e FunçõesEstrutura de Dados - Aula 03 - Ponteiros e Funções
Estrutura de Dados - Aula 03 - Ponteiros e Funções
Leinylson Fontinele
 
Arquitetura de-computadores
Arquitetura de-computadoresArquitetura de-computadores
Arquitetura de-computadores
Pimentel
 
SI - Introdução a Sistemas Distribuidos
SI - Introdução a Sistemas DistribuidosSI - Introdução a Sistemas Distribuidos
SI - Introdução a Sistemas Distribuidos
Frederico Madeira
 
Algoritmos e Estrutura de Dados - Aula 02
Algoritmos e Estrutura de Dados - Aula 02Algoritmos e Estrutura de Dados - Aula 02
Algoritmos e Estrutura de Dados - Aula 02
thomasdacosta
 
Lista de exercícios em Bash (resolvida)
Lista de exercícios em Bash (resolvida) Lista de exercícios em Bash (resolvida)
Lista de exercícios em Bash (resolvida)
Marcelo Barros de Almeida
 
Normalização - Alexandruk
Normalização - AlexandrukNormalização - Alexandruk
Normalização - Alexandruk
Hebert Alquimim
 
Sistemas Operacionais - Aula 08 (Sincronização e Comunicação entre Processos)
Sistemas Operacionais - Aula 08 (Sincronização e Comunicação entre Processos)Sistemas Operacionais - Aula 08 (Sincronização e Comunicação entre Processos)
Sistemas Operacionais - Aula 08 (Sincronização e Comunicação entre Processos)
Leinylson Fontinele
 
Matéria de apoio (Base de dados)
Matéria de apoio  (Base de dados)Matéria de apoio  (Base de dados)
Matéria de apoio (Base de dados)
André Silva
 
Mini curso de banco de dados - parte 1
Mini curso de banco de dados - parte 1Mini curso de banco de dados - parte 1
Mini curso de banco de dados - parte 1
Rafael Sanches
 
Comandos CMD
Comandos CMDComandos CMD
Comandos CMD
Joao Andre Picao
 
Respostas exercício 1 bdi
Respostas exercício 1   bdiRespostas exercício 1   bdi
Respostas exercício 1 bdi
Patty Muniz
 
Estrutura de dados - Aula de Revisão (Linguagem C/C++, Função, Vetor, Matriz,...
Estrutura de dados - Aula de Revisão (Linguagem C/C++, Função, Vetor, Matriz,...Estrutura de dados - Aula de Revisão (Linguagem C/C++, Função, Vetor, Matriz,...
Estrutura de dados - Aula de Revisão (Linguagem C/C++, Função, Vetor, Matriz,...
Leinylson Fontinele
 
Clock
ClockClock
Estrutura de Dados - Grafos
Estrutura de Dados - GrafosEstrutura de Dados - Grafos
Estrutura de Dados - Grafos
Leinylson Fontinele
 
03 mer2
03 mer203 mer2
03 mer2
Fabiano Sales
 
Hardware
HardwareHardware
Hardware
Jakson Silva
 
2019-2 - Algoritmos - Aula 06 A - Tomada de Decisão
2019-2 - Algoritmos - Aula 06 A - Tomada de Decisão2019-2 - Algoritmos - Aula 06 A - Tomada de Decisão
2019-2 - Algoritmos - Aula 06 A - Tomada de Decisão
Rodrigo Kiyoshi Saito
 

What's hot (20)

Sistema de arquivos
Sistema de arquivosSistema de arquivos
Sistema de arquivos
 
Conectividade em grafos
Conectividade em grafosConectividade em grafos
Conectividade em grafos
 
Soa cap2 exercicios resolvidos shell
Soa cap2 exercicios resolvidos shellSoa cap2 exercicios resolvidos shell
Soa cap2 exercicios resolvidos shell
 
Estrutura de Dados - Aula 03 - Ponteiros e Funções
Estrutura de Dados - Aula 03 - Ponteiros e FunçõesEstrutura de Dados - Aula 03 - Ponteiros e Funções
Estrutura de Dados - Aula 03 - Ponteiros e Funções
 
Arquitetura de-computadores
Arquitetura de-computadoresArquitetura de-computadores
Arquitetura de-computadores
 
SI - Introdução a Sistemas Distribuidos
SI - Introdução a Sistemas DistribuidosSI - Introdução a Sistemas Distribuidos
SI - Introdução a Sistemas Distribuidos
 
Algoritmos e Estrutura de Dados - Aula 02
Algoritmos e Estrutura de Dados - Aula 02Algoritmos e Estrutura de Dados - Aula 02
Algoritmos e Estrutura de Dados - Aula 02
 
Lista de exercícios em Bash (resolvida)
Lista de exercícios em Bash (resolvida) Lista de exercícios em Bash (resolvida)
Lista de exercícios em Bash (resolvida)
 
Normalização - Alexandruk
Normalização - AlexandrukNormalização - Alexandruk
Normalização - Alexandruk
 
Sistemas Operacionais - Aula 08 (Sincronização e Comunicação entre Processos)
Sistemas Operacionais - Aula 08 (Sincronização e Comunicação entre Processos)Sistemas Operacionais - Aula 08 (Sincronização e Comunicação entre Processos)
Sistemas Operacionais - Aula 08 (Sincronização e Comunicação entre Processos)
 
Matéria de apoio (Base de dados)
Matéria de apoio  (Base de dados)Matéria de apoio  (Base de dados)
Matéria de apoio (Base de dados)
 
Mini curso de banco de dados - parte 1
Mini curso de banco de dados - parte 1Mini curso de banco de dados - parte 1
Mini curso de banco de dados - parte 1
 
Comandos CMD
Comandos CMDComandos CMD
Comandos CMD
 
Respostas exercício 1 bdi
Respostas exercício 1   bdiRespostas exercício 1   bdi
Respostas exercício 1 bdi
 
Estrutura de dados - Aula de Revisão (Linguagem C/C++, Função, Vetor, Matriz,...
Estrutura de dados - Aula de Revisão (Linguagem C/C++, Função, Vetor, Matriz,...Estrutura de dados - Aula de Revisão (Linguagem C/C++, Função, Vetor, Matriz,...
Estrutura de dados - Aula de Revisão (Linguagem C/C++, Função, Vetor, Matriz,...
 
Clock
ClockClock
Clock
 
Estrutura de Dados - Grafos
Estrutura de Dados - GrafosEstrutura de Dados - Grafos
Estrutura de Dados - Grafos
 
03 mer2
03 mer203 mer2
03 mer2
 
Hardware
HardwareHardware
Hardware
 
2019-2 - Algoritmos - Aula 06 A - Tomada de Decisão
2019-2 - Algoritmos - Aula 06 A - Tomada de Decisão2019-2 - Algoritmos - Aula 06 A - Tomada de Decisão
2019-2 - Algoritmos - Aula 06 A - Tomada de Decisão
 

Similar to Family tree in java

1.1 motivation
1.1 motivation1.1 motivation
1.1 motivation
futurespective
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
BTI360
 
1.1 motivation
1.1 motivation1.1 motivation
1.1 motivation
Ruud van Vliet
 
1.1 motivation
1.1 motivation1.1 motivation
1.1 motivation
Amir Mardani
 
Design, implement, test(In Java ) a doubly linked list ADT, using DL.pdf
Design, implement, test(In Java ) a doubly linked list ADT, using DL.pdfDesign, implement, test(In Java ) a doubly linked list ADT, using DL.pdf
Design, implement, test(In Java ) a doubly linked list ADT, using DL.pdf
trishacolsyn25353
 
BEKK Teknologiradar - Kotlin
BEKK Teknologiradar - KotlinBEKK Teknologiradar - Kotlin
BEKK Teknologiradar - Kotlin
Vegard Veiset
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
NicholasflqStewartl
 
Scala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timeScala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en time
karianneberg
 
Bài tập và bài tập nâng cao của cây AVL.docx
Bài tập và bài tập nâng cao của cây  AVL.docxBài tập và bài tập nâng cao của cây  AVL.docx
Bài tập và bài tập nâng cao của cây AVL.docx
LNhi89
 
Scala - THE language for Big Data
Scala - THE language for Big DataScala - THE language for Big Data
Scala - THE language for Big Data
Tzach Zohar
 
I need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdfI need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdf
allurafashions98
 
Write the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdfWrite the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdf
fckindswear
 
Rd
RdRd
Pure Kotlin Devoxx PL 2021
Pure Kotlin Devoxx PL 2021Pure Kotlin Devoxx PL 2021
Pure Kotlin Devoxx PL 2021
Jarek Ratajski
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
Codecamp Romania
 
From java to kotlin beyond alt+shift+cmd+k
From java to kotlin beyond alt+shift+cmd+kFrom java to kotlin beyond alt+shift+cmd+k
From java to kotlin beyond alt+shift+cmd+k
Fabio Collini
 
Scala == Effective Java
Scala == Effective JavaScala == Effective Java
Scala == Effective Java
Scalac
 
2.1 Recap From Day One
2.1 Recap From Day One2.1 Recap From Day One
2.1 Recap From Day One
retronym
 
C# 6.0
C# 6.0C# 6.0
C# 6.0
Can BAKIR
 
Scala introduction
Scala introductionScala introduction
Scala introduction
Alf Kristian Støyle
 

Similar to Family tree in java (20)

1.1 motivation
1.1 motivation1.1 motivation
1.1 motivation
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
1.1 motivation
1.1 motivation1.1 motivation
1.1 motivation
 
1.1 motivation
1.1 motivation1.1 motivation
1.1 motivation
 
Design, implement, test(In Java ) a doubly linked list ADT, using DL.pdf
Design, implement, test(In Java ) a doubly linked list ADT, using DL.pdfDesign, implement, test(In Java ) a doubly linked list ADT, using DL.pdf
Design, implement, test(In Java ) a doubly linked list ADT, using DL.pdf
 
BEKK Teknologiradar - Kotlin
BEKK Teknologiradar - KotlinBEKK Teknologiradar - Kotlin
BEKK Teknologiradar - Kotlin
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
 
Scala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timeScala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en time
 
Bài tập và bài tập nâng cao của cây AVL.docx
Bài tập và bài tập nâng cao của cây  AVL.docxBài tập và bài tập nâng cao của cây  AVL.docx
Bài tập và bài tập nâng cao của cây AVL.docx
 
Scala - THE language for Big Data
Scala - THE language for Big DataScala - THE language for Big Data
Scala - THE language for Big Data
 
I need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdfI need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdf
 
Write the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdfWrite the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdf
 
Rd
RdRd
Rd
 
Pure Kotlin Devoxx PL 2021
Pure Kotlin Devoxx PL 2021Pure Kotlin Devoxx PL 2021
Pure Kotlin Devoxx PL 2021
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
From java to kotlin beyond alt+shift+cmd+k
From java to kotlin beyond alt+shift+cmd+kFrom java to kotlin beyond alt+shift+cmd+k
From java to kotlin beyond alt+shift+cmd+k
 
Scala == Effective Java
Scala == Effective JavaScala == Effective Java
Scala == Effective Java
 
2.1 Recap From Day One
2.1 Recap From Day One2.1 Recap From Day One
2.1 Recap From Day One
 
C# 6.0
C# 6.0C# 6.0
C# 6.0
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 

More from Programming Homework Help

Java Assignment Help
Java  Assignment  HelpJava  Assignment  Help
Java Assignment Help
Programming Homework Help
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
Programming Homework Help
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
Programming Homework Help
 
Binary tree in java
Binary tree in javaBinary tree in java
Binary tree in java
Programming Homework Help
 
Bank account in java
Bank account in javaBank account in java
Bank account in java
Programming Homework Help
 
Mouse and Cat Game In C++
Mouse and Cat Game In C++Mouse and Cat Game In C++
Mouse and Cat Game In C++
Programming Homework Help
 
Word games in c
Word games in cWord games in c
Word games in c
Programming Homework Help
 
Card Games in C++
Card Games in C++Card Games in C++
Card Games in C++
Programming Homework Help
 

More from Programming Homework Help (8)

Java Assignment Help
Java  Assignment  HelpJava  Assignment  Help
Java Assignment Help
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
 
Binary tree in java
Binary tree in javaBinary tree in java
Binary tree in java
 
Bank account in java
Bank account in javaBank account in java
Bank account in java
 
Mouse and Cat Game In C++
Mouse and Cat Game In C++Mouse and Cat Game In C++
Mouse and Cat Game In C++
 
Word games in c
Word games in cWord games in c
Word games in c
 
Card Games in C++
Card Games in C++Card Games in C++
Card Games in C++
 

Recently uploaded

Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
Chevonnese Chevers Whyte, MBA, B.Sc.
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Leena Ghag-Sakpal
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 

Recently uploaded (20)

Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 

Family tree in java

  • 1. s
  • 2. Family Tree in Java This program is finding its parent grandparent and siblings. There are methods to find the grandchildren, most similar descendant, etc. import java.util.ArrayList; import java.util.List; public class FamilyTree { Tree t; public FamilyTree(Tree t) { this.t = t; } public String getParent(Node person) { if (person.getParent() == null) return "No parent"; return (String) person.getParent().getElement(); } public String getGrandparent(Node person) { if (person.getParent() == null || person.getParent().getParent() == null) return "No grandparent"; return (String) person.getParent().getParent().getElement(); } public List<String> getChildren(Node person) { List<String> children = new ArrayList<String>(); for (Node child : person.getChildren()) { children.add((String) child.getElement()); } return children; } public List<String> getGrandchildren(Node person) { List<String> grandchildren = new ArrayList<String>(); for (Node child : person.getChildren()) {
  • 3. grandchildren.addAll(getChildren(child)); } return grandchildren; } public List<String> getSiblings(Node person) { List<String> siblings = new ArrayList<String>(); if (person.getParent() == null) return siblings; for (Node sibling : person.getParent().getChildren()) { if (sibling != person) siblings.add((String) sibling.getElement()); } return siblings; } public int getSimilarityScore(String a, String b) { int score = 0; int minLength = Math.min(a.length(), b.length()); for (int i = 0; i < minLength; i++) { if (a.charAt(i) == b.charAt(i)) score++; else break; } return score; } public String mostSimilarDescendant(Node person) { if (person.getChildren().isEmpty()) return null; String mostSimilar = null; int mostSimilarScore = -1; for (String child : getChildren(person)) { int score = getSimilarityScore((String) person.getElement(), child); if (score > mostSimilarScore) { mostSimilar = child; mostSimilarScore = score; } } for (String grandchild : getGrandchildren(person)) { int score = getSimilarityScore((String) person.getElement(), grandchild);
  • 4. if (score > mostSimilarScore) { mostSimilar = grandchild; mostSimilarScore = score; } } return mostSimilar; } }