CS代考 COMP1110 Exam, Question 1.2

package comp1110.exam;

import java.util.List;

Copyright By PowCoder代写 加微信 powcoder

* COMP1110 Exam, Question 1.2
public class Q1FamilyTree {

* This class represents an individual with zero or more children.
static class Individual {
public String name;
* This individual’s immediate descendants.
* If this individual has no children, this field is null.
public Individual[] children;

public Individual(String name, Individual[] children) {
this.name = name;
this.children = children;

* This function accepts an Individual ancestor representing
* the root (common ancestor) of a family tree
* and the name of a target individual to find within that family tree,
* and returns a string representation of all the ancestors of that
* individual, each separated by the string ” born of “.
* If target name matches the name of ancestor, then only
* the target name is returned.
* If the target name is not found within the family tree descended from
* ancestor, then null is returned.
* For example, given an Individual homer representing a person named
* “Homer”, who has children named “Lisa” and “Bart”:
* getAncestry(homer, “Lisa”) returns “Lisa born of Homer”;
* getAncestry(homer, “Bart”) returns “Bart born of Homer”; and
* getAncestry(homer, “Homer”) returns “Homer”; and
* getAncestry(homer, “Barney”) returns null
* Note: each individual has only one parent in the family tree.
* @param ancestor the root (common ancestor) of a family tree
* @param targetName the name of an individual to find in the family tree
* @return a String representing the ancestry of the individual named
* targetName, or null if no such individual is found
public static String getAncestry(Individual ancestor, String targetName) {
// FIXME complete this method
return “”;

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com