• 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

    • Xbox June Update brings unsynced save management, publisher browsing, and more by Pulasthi Ariyasinghe June has been a busy month for Microsoft, bringing major software upgrades across its product stack. It even announced new hardware for its Xbox lineup, finally entering the handheld gaming space. The company's roundup for this month's new features has now been published, and it's touting a great deal of changes. To start off on the PC side, the Xbox app on the platform now has a section to browse by publishers. The company says that this will let players easily discover more games made by their favorite developers and franchises. Copilot for Gaming also landed in beta form recently, letting users ask AI for help when a game gets too difficult. It's only available for iOS and Android for now, with ROG Xbox Ally support coming later this year. Another feature that will hit the Xbox Ally is the new universal launcher feature for the Xbox app on PC. Microsoft just kicked off Xbox Insider testing for this functionality earlier today. Get all the details here. Over on consoles, the ability to hide system apps, pin favorites to the list, and reduce the number of tiles displayed are now available. Game Hubs also arrived as a fresh feature to easily display relevant information when selecting a game to play, offering data on player stats, achievements, friends currently playing, recent captures, available add-ons, events, and more. Double-tapping the play button will quick-launch the game instead. On both Xbox consoles and in the cloud, a new progress bar will now appear when a save has been left behind on a device in an offline state. "A new progress bar, device names, timestamps, and additional details are now displayed when you have previous game saves on another device in an unsynced state," says the company. Microsoft has also added mouse and keyboard controls as well as touch controls for more cloud games this month. These join the fresh additions that have landed on the 'Stream your own game' collection and the Retro Classics app. Check out the full lists on the announcement page here. On top of all this, Microsoft has also announced that Xbox will be at Gamescom this year. While no details have been announced yet, more announcements from Xbox Game Studios may happen at the major gaming event.
    • Hopefully this is a precurser to them linking other launchers to the Xbox console. With this current gen the Xbox has had dismal sales compared to the competition. If they did support Steam, Epic, Ubisoft Connect, etc etc they'd crush on the next gen battle.
    • My update. Didn't see much point in the top panel since global menu isn't there, so going with a win/kde layout now. Overall, I would say Gnome is a disappointment - it's been 15 years and you still have to rely on a bunch of extensions to get anything useful out of it. At the same time, the way Universal Blue / Bluefin is approaching the desktop feels like what Ubuntu should have started doing five years ago (no wonder the guy I learned about this from used to work for Canonical). Maybe I should have gone with Aurora (the KDE variant), or Bazzite with KDE, but I think I have Gnome where it works for me now.       
    • GOG Galaxy offers connecting of other launchers into theirs. And while idea is interesting, I always had issues with Steam that would just lose connection and just not work. Which was annoying.
    • I remember that during the earlier development of Windows 10 a big deal was made about the Recycle Bin icon(s). https://www.neowin.net/news/wi...pdated-icons-in-this-build/
  • Recent Achievements

    • Dedicated
      Camlann earned a badge
      Dedicated
    • Week One Done
      fredss earned a badge
      Week One Done
    • Dedicated
      fabioc earned a badge
      Dedicated
    • One Month Later
      GoForma earned a badge
      One Month Later
    • Week One Done
      GoForma earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      647
    2. 2
      Michael Scrip
      226
    3. 3
      ATLien_0
      221
    4. 4
      +FloatingFatMan
      143
    5. 5
      Xenon
      136
  • Tell a friend

    Love Neowin? Tell a friend!