• 0

[Java] Need some help please!


Question

hi guuys, have this assignment and the idea is to read in a file of the following format:

Film / Actor / Actor / Actor / Actor

Film / Actor / Actor

etc.

i then have to save this data in some way so that i can perform six degrees of separation test to kevin bacon. so the user will input the name of an actor or actress and it will tell you how many steps and who it links to kevin bacon.

now i understand in concept. and think the best idea is to use a shortest route algorithm on a graphing structure. but i have no idea how to get from the text file into a format i can do that on.

any help would be much appreciated.

Martin

Link to comment
https://www.neowin.net/forum/topic/840038-java-need-some-help-please/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

That doesn't sound difficult.

Every actor should be linked to all the other actors they have starred with. So you have an 'Actor' class which contains references to other 'Actor's they have worked with, maybe an ArrayList of 'Actor's or something.

So, read in the first line:

Goldeneye / Pierce Brosnan / Sean Bean / Izabella Scorupco

Now, Brosnan is linked to Bean and Scorupco

Bean to Brosnan and Scorupco

Scorupco to Brosnan and Bean.

So if you read in another line such as:

Die Another Day / Pierce Brosnan / Halle Berry

Brosnan now gets linked to Halle Berry

And Berry to Brosnan

Once everything is read in, use Dijkstra's algorithm (http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) to find the shortest path between all the actors (or in your case between Kevin Bacon and the others).

  • 0

thanks for the help so far guys. have got my input sorted. scanner is working well with a delimiter set for the /. however, i still dont quite know how to work it. right now i have two classes, film and actor. film has a title and an arraylist of actors. but actor only has a name. i cant see how its going to link to the other actors. any ideas?

thanks again

  • 0

What you need to do is have a map from the actors name to the degree of separation.

Kevin Bacon is 0

People who worked in the same movie as bacon are 1

people who worked with these other people are 2 and so on

You should do a pass to search for Kevin Bacon and then set all of the people who worked with im to 1

Then you should do another pass to search for people who worked with them and set them to 2 (unless they're already set to something lower than 2, of course)

You will repeat the same thing with incrementing numbers.

There's probably a more efficient way but this will work.

Just thought you could use a sort of tree too.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.