Is there something in java i can use that will hold multiple strings ? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

Is there something in java i can use that will hold multiple strings ?

I have a section in my program where you can set member of the family tree's relations. For example I have the user enter strings like : Jr is a parent of Tre. The problem is i don't know what i can use that will hold Jr's children tre , jay, and dee. And i would also like to have some type of code that will create something new to distinguish when a new parent comes only with different children. This is what i have so far https://code.sololearn.com/cC0N3O84iUgd/#java

4th Nov 2018, 6:47 PM
Rubii4
Rubii4 - avatar
5 Réponses
+ 2
Ralf Lukner yes that's what I want. I want the user to be able to input Jr parents Tre. And to have something also distinguish that Jane parents James. And have something keep trace of the relation or children.
4th Nov 2018, 9:09 PM
Rubii4
Rubii4 - avatar
0
Are you familiar with Arrays or other collections? You might be able to use an array of strings to represent a person's children, like: String[] children = ["child1name", "child2name", "child3name"]
4th Nov 2018, 8:51 PM
Anthony
0
You use the s (set) option of your program to set relationships.
4th Nov 2018, 9:02 PM
Ralf Lukner
Ralf Lukner - avatar
0
how about something like this: public class Person implements Comparable<Person>{ public static enum Sex { MALE, FEMALE; } private int refnr; private String name; private Sex sex; private Date birthdate; private Date deathdate; private Person father; private Person mother; private Person spouse; private ArrayList<Person> children; private ArrayList<Person> exspouses;
4th Nov 2018, 9:14 PM
Ralf Lukner
Ralf Lukner - avatar
0
you create an a propery for the things a person has ... an ArrayList<Person> to store the children
4th Nov 2018, 9:17 PM
Ralf Lukner
Ralf Lukner - avatar