``````/*
Problem statement...

You go to a wedding reception, and there are a lot of people. All of these
people 'know' the bride or the groom in some manner. Additionally, a lot of
them may know each other in one or more manner. For example, let's take Ann
and David, who meet by the coffee machine.

Ann is the bride's sister.
David is the groom's boss at work.
Ann is going out with David's brother Cain.

So - if you look at the relationships between these two, you have:

Ann goes out with Cain. Cain is a brother of David.
Ann is a sister of Bride. Bride is married to Groom. Groom works for David.

So here's the problem...

Assume a Table (the table will be mocked up in memory)...

The Table has entries for each person's relationships to people at the wedding.

The problem is to write a RECURSIVE method that will take the names
of two people as input. It then needs to output all the ways in which
these people are related, much in the same fashion as we showed in the list of
relationships between Ann and David above.  You must show all associations between
these two people - direct and indirect.

----- Make sure to write a brief description of your solution. -----

----- Discuss conditions that can produce non-terminating recursion. -----
*/

package com.oneshield.test;

import java.util.ArrayList;

public class WeddingTester
{
ArrayList assocations = new ArrayList();

public static void main(String[] args)
{
WeddingTester tester = new WeddingTester();

tester.test();
}

/**
* Add methods and variables as needed...
*/
public void test()
{
try
{
}
catch(Exception ex)
{
ex.printStackTrace();
}
}

/**
* This method is used to search for a persons associations
*
*
* @param person - The name of the person to find associations for...
* @return - An ArrayList of Associations
*/
public ArrayList getAssociatedPersons(String person)
{
ArrayList associatedPersons = new ArrayList();

for(int i=0; i<assocations.size(); i++)
{
ArrayList column = (ArrayList)assocations.get(i);

String columnPerson = (String)column.get(0);

if(person.equalsIgnoreCase(columnPerson))
{
}
}

if(associatedPersons.isEmpty())
{
associatedPersons = null;
}

return associatedPersons;
}

/**
* Initialize a 2-dimensional array - this array serves as a mockup (in-memory) database table
*
* This data structure should contain entries for all people at the wedding and their relationships
*
* See the sample data below
*
*/
public void initialize()
{
ArrayList columns = new ArrayList();
}

/**
* Databean - an association for a person
*/
public class AssociationBean
{
String person1 = null;
String assocation = null;
String person2 = null;

public AssociationBean(String person1, String assocation, String person2)
{
this.person1 = person1;

this.assocation = assocation;

this.person2 = person2;
}

* @see java.lang.Object#toString()
*/
public String toString()
{
StringBuffer buffer = new StringBuffer();

buffer.append(person1);
buffer.append("-");
buffer.append(assocation);
buffer.append("-");
buffer.append(person2);

return buffer.toString();
}

/**
* @return Returns the assocation.
*/
public String getAssocation()
{
return assocation;
}

/**
* @param assocation The assocation to set.
*/
public void setAssocation(String assocation)
{
this.assocation = assocation;
}

/**
* @return Returns the person.
*/
public String getPerson1()
{
return person1;
}

/**
* @param person The person to set.
*/
public void setPerson1(String person1)
{
this.person1 = person1;
}

/**
* @return Returns the person.
*/
public String getPerson2()
{
return person2;
}

/**
* @param person The person to set.
*/
public void setPerson2(String person2)
{
this.person2 = person2;
}
}
}
``````

Edited by mike_2000_17: Fixed formatting

4
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by verruckt24

you cannot expect to post your assignment and get a solution. please use code tags, and identify the relevant code to post.

In addition to what he said above, if at all possible, don't post your assignment explanation, just post whatever information is relevant to helping you solve your problem. If you've identified the problematic code, this means telling us what the code is supposed to be doing and telling us what it is doing etc. Reading your entire project description isn't usually necessary.

From your program I don't see any OOP concepts into play here. Create a class Person, create a class Relation which determines the type of relationship (this could be a string representing the relation). Create a class Association that has a Relation object and a Person object. Then you could model your application accordingly.
Example : Imagine two brothers being married to two sisters. So here you have some people with multiple relations within them. Person A is the brother-in-law of Person B, Person B is sister-in-law of Person A. To depict this situation in your model, you have two person objects A and B. You have two Relation objects "brother-in-law" and "sister-in-law". Now Person A has an Association object within itself, which itself has a Relation object "brother-in-law" and Person B objects' reference.
I hope you get it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.