Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming / Recursion Below is an assignment that I'm not even sure how to approach. The I'm not sure how to really deal with

Java Programming / Recursion

Below is an assignment that I'm not even sure how to approach. The I'm not sure how to really deal with reading the input files and then using the recursive methods described below. Help would be appreciated. Thanks.

Assume that you have data about people who are interconnected to each other by friend relationship. Here, friend is a bi-directional relationship. For example, assume that there are six people and the friend relationships among them are:

Smith is a friend of Mankell (and vice versa)

Adams is a friend of Steward (and vice versa)

Adams is a friend of Yorst (and vice versa)

Stein is a friend of Mankell (and vice versa)

Then, given the name of a person, you want to find every person who is a friend of that person, directly or indirectly. For example, given Smith, you want to be able to find that Mankell and Stein are his friends. Mankell is a direct friend of Smith and Stein is an indirect friend through Mankell. If given Yorst, you want to be able to find that Adams (directly) and Steward (indirectly through Adams) are her friends.

Your task is to read the friend relationship from an input file and find all friends of a person whose name a user enters.

More specifically, your program must perform the following:

When your program starts, it must display the following prompt:

Enter then name of a person whose friends you want to find (enter 0 for exit):

Then, your program must find and display all friends of the person. After displaying the friends names, your program must display the above prompt. This is repeated until the user enters 0.

The format of the input file is:

6

Smith Adams Steward Stein Mankell Yorst

Smith 0 0 0 0 1 0

Adams 0 0 1 0 0 1

Steward 0 1 0 0 0 0

Stein 0 0 0 0 1 0

Mankell 1 0 0 1 0 0

Yorst 0 1 0 0 0 0

The first line has the number of people in this input file. Below the first line is a two-dimensional matrix, where columns and rows are names of people. The number 1 in an entry in the matrix indicates the two people corresponding to the column and the row are friends with each other. For example, 1 in the first row (not counting the top row that has names) indicates that Smith is a friend of Mankell and Makell is a friend of Smith. The number 0 in an entry in the matrix indicates the two people corresponding to the column and the row are not friends with each other. For example, the first 0 in the first row (again, not counting the top row that has names) of the matrix indicates that Smith is not a friend of Adams and Adams is not a friend of Smith. Since the friend is a bi-directional relationship, the matrix is a symmetric matrix.

Practice of implementation of recursion. So, your program must use recursion when finding all friends of a person. You may use any data structure you want to write this program.

Source code

Name the program as AllFriends.java. Even though you have a separate documentation, you still need to include sufficient comments within the source code.

Test your program with a couple of different input files, each of which stores some friend relationships among people.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

What is the primary opportunity for new firms in a mature industry?

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago