• 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

    • It's a 3v3 fighting system which Mortal Kombat has never done, unless you are talking about the hitstop animation and so on
    • Apple's future is glass-centric, and the new glassy UI is just the beginning  by Hamid Ganji Apple will unveil its overhauled UI experience at today’s WWDC event. The new UI will be available on all Apple devices, including iPhones, iPads, and Mac devices, and it will take most of its cues from visionOS. Bloomberg’s Mark Gurman has now provided us with new details about Apple’s new UI. The new interface is called Liquid Glass and has “sheen and see-through visuals of a glassy surface.” The name represents Apple’s approach to designing the new interface. The new UI also brings “transparency and shine effects in all of Apple’s tool bars, in-app interfaces and controls.” However, Gurman notes that the Liquid Glass interface will lay the groundwork for Apple’s future products, especially the 20th anniversary iPhone. It was already reported that Apple plans to unveil at least two new devices in 2027, which coincides with the iPhone’s 20th anniversary. The first model would be the long-awaited foldable iPhone. However, the second model, the 20th anniversary iPhone, is a glass-centric model that aligns with Apple’s new UI concept. According to Gurman, the 20th anniversary iPhone has curved glass sides and edges. It also features “extraordinarily slim bezels” and “no cutout section in the screen.” The phone is reportedly called “Glasswing,” which refers to the type of butterfly with transparent wings. Apple’s upcoming iOS 26 is the biggest overhaul to iPhone UI since the launch of iOS 7 in 2013. The new UI also hits iPadOS 26, tvOS 26, visionOS 26, watchOS 26, macOS 26. As a side note, the new “26” on the name of Apple’s operating system represents the year 2026.
    • Listen, adrynalyne - You're trolling me (I've known this for months). If you have something meaningful to say - say it, don't ask as if you know something, becauser you know sh*t. Ok?
  • Recent Achievements

    • Week One Done
      Al_ earned a badge
      Week One Done
    • 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
  • Popular Contributors

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

    Love Neowin? Tell a friend!