Question
While using java what would we need to add in order to find the siblings of a specific person? private void processParents(Scanner input) { while
While using java what would we need to add in order to find the siblings of a specific person?
private void processParents(Scanner input) { while (input.hasNextLine()) { String personName = input.nextLine(); String motherName = input.nextLine(); String fatherName = input.nextLine(); Person p = find(personName); if (!motherName.equals("unknown")) { Person mother = find(motherName); p.setMother(mother); mother.addChild(p); } if (!fatherName.equals("unknown")) { Person father = find(fatherName); p.setFather(father); father.addChild(p); }
import java.util.*;
public class Person { private String name; private Person mother; private Person father; private ArrayList
public Person(String name) { this.name = name; this.children = new ArrayList
public String getName() { return this.name; }
public Person getMother() { return this.mother; }
public Person getFather() { return this.father; }
public ArrayList
public void setFather(Person father) { this.father = father; }
public void addChild(Person child) { this.children.add(child); } }
// WE NEED TO ADD SOMETHING IN ORDER TO FIND THE SIBLINGS OF A PERSON
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started