Person harry =newPerson("Harry Potter",false,1980);
Person james =newPerson("James Sirius",false,2005, ginny, harry);
Person albus =newPerson("Albus Severus",false,2006, ginny, harry);
Person lily =newPerson("Lily Luna",true,2007, ginny, harry);
//Implement the Person.isCousin(Person p) which returns true if they are first cousins.
// X and Y are first cousins if one of their parents are siblings.
System.out.println("Are rose and albus cousins? "+ rose.isCousinOf(albus));
System.out.println("Are albus and rose cousins? "+ albus.isCousinOf(rose));
System.out.println("Are harry and ron cousins? "+ harry.isCousinOf(ron));
System.out.println("Are lily and charlie cousins? "+ lily.isCousinOf(charlie));
System.out.println("Are james and albus cousins? "+ james.isCousinOf(albus));
System.out.println("Are james and fred cousins? "+ james.isCousinOf(fred));
System.out.println("Are james and hugo cousins? "+ james.isCousinOf(hugo));
System.out.println("Are james and rose cousins? "+ james.isCousinOf(rose));
}
}
We use cookies to provide, improve, protect and promote our services. Visit our Privacy Policy and Privacy Policy FAQs to learn more. You can manage your personal preferences, including your ‘Do not sell or share my personal data to third parties’ setting using the “Customize cookies” button below.