• 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.
  • Posts

    • The new official logo of the GOP
    • Linux 6.16-rc1 is out: What's new and what does it mean for your system? by Paul Hill Linus Torvalds, head and founder of the Linux kernel, has announced the closure of the merge window where major new features are added to the kernel, and the beginning of the Linux 6.16 release candidates, beginning with release candidate 1 (Linux 6.16-rc1). Linux 6.15 was released two weeks ago and in the time since, developers have had the opportunity to try and get their new kernel features into the Linux 6.16 kernel. Over the next two months, we will get seven or eight release candidates where developers will stabilize new and existing features. This means that the stable version of Linux 6.16 will arrive around the end of July. Torvalds said that the merge window seemed pretty normal this time, but did say he had a feeling that there were more “late straggler” pull requests than is typical. Despite this, everything seems to be fine and the schedule will be going forward as planned. Key areas of development Torvalds explained that around half of the changes in the first release candidate were driver updates, with the bulk of those being made up with by GPU and networking drivers. For end users these are the most important changes because when your favorite distribution of Linux ships a new release with this kernel, it will support more graphics cards and networking equipment like Wi-Fi cards. The non-driver updates in this version are split between architecture-specific updates, documentation and tooling (perf tool and selftests), and core changes to filesystems, core kernel, memory management, and networking. Torvalds said the core changes include some of the “most important” changes, though they’re not necessarily major changes. Fixes to the core ensure a more stable Linux kernel for end users, plus better performance. The merge window saw developers submit thousands of non-merge commits and merges. The non-merge commits were around 13,000 while the merge commits nearly reached 1,000. There were 1,783 unique authors submitting code during this window. Next steps Over the coming weeks, Linux developers, including individuals or representatives of companies, will submit bug fixes for new and existing features. This release candidate cycle will run until around the end of July and then the final version will become available. End users shouldn’t go out and download Linux 6.16 when it’s released, instead just wait for your Linux distribution to update to it, as distribution-specific changes get made. Neowin will be following these releases and reporting on any interested changes that are noted. Source: LKML
    • There was no cancelation. Microsoft delayed work on it to focus on further tuning the OS and improving the OS experience overall, before going full core into a direct hardware battle with their partners.
    • As someone who has 500+ hours of playtime on Anno 1800, all I can say is shut up and take my money.
  • Recent Achievements

    • Week One Done
      MadMung0 earned a badge
      Week One Done
    • Reacting Well
      BlakeBringer earned a badge
      Reacting Well
    • Reacting Well
      Lazy_Placeholder earned a badge
      Reacting Well
    • Dedicated
      Epaminombas earned a badge
      Dedicated
    • Veteran
      Yonah went up a rank
      Veteran
  • Popular Contributors

    1. 1
      +primortal
      469
    2. 2
      +FloatingFatMan
      273
    3. 3
      ATLien_0
      242
    4. 4
      snowy owl
      210
    5. 5
      Edouard
      182
  • Tell a friend

    Love Neowin? Tell a friend!