So I am creating the Kevin Bacon Game for my java class.
These are the files of names I gotta use
Actors:
Leonardo Dicaprio
Susan Sarandon
Tom Hanks
Robert De Niro
Barack Obama
Helen Keller
Katharine Cornell
Helen Hayes
John Laughlin
Mark Zuckerberg
Joe Lipari
Welker White
The relationships:
Susan Sarandon | Tom Hanks : Cloud Atlas
Tom Hanks | Kevin Bacon : Apollo 13
Leonardo Dicaprio | Kevin Bacon : This Boy's Life
Robert De Niro | Kevin Bacon : This Boy's Life
Barack Obama | Tom Hanks : the Road We've Traveled
Helen Keller | Katharine Cornell : Helen Keller in Her Story
Katharine Cornell | Helen Hayes : Stage Door Canteen
Helen Hayes | John Laughlin : Murder with Mirrors
John Laughlin | Kevin Bacon : Footloose
Mark Zuckerberg | Joe Lipari : Terms and Conditions May Apply
Joe Lipari | Welker White : Eat Pray Love
Welker White | Kevin Bacon : Lemon Sky
This is the program I have now:
package Game;
import java.io.*;
import java.util.HashMap;
import java.util.Scanner;
import java.util.regex.Pattern;
/**
* @author
*
*/
public class BaconNumber
{
/**
* @param args
*/
private HashMap<String,String> relationships;
private HashMap<String,String> actors;
public static void main(String[] args)
throws FileNotFoundException
{
Scanner input = new Scanner(new File("relationships"));
HashMap<String, String> relationships = new HashMap<String, String>();
while (input.hasNextLine()) {
String[] columns = input.nextLine().split(Pattern.quote(" | "));
relationships.put(columns[0], columns[1]);
}
System.out.println(relationships);
}
public BaconNumber()
{
relationships = new HashMap<String,String>();
actors = new HashMap<String,String>();
}
public void printActors() throws FileNotFoundException
{
Scanner input = new Scanner(new File("actors"));
while (input.hasNextLine())
{
System.out.println(input.nextLine());
}
}
public int getBaconNumber( String actor , int number)
{
if( actor == "Kevin Bacon")
{
return number;
}
else
{
relationships.get(actor);
System.out.println(actor + " starred in " + relationships.value + "with" + relationships.value );
System.out.println( " The Bacon Number for " + actor + " is " + number );
return number; // fix this
}
relationships.containsKey("Kevin Bacon")
// {
// number++;
// System.out.println(" The bacon number for" + actor + " is " + number );
// }
// else
// {
//
// }
}
}
I need some help with my getBaconNumber(), I need the program to look up the actor and to calculate the bacon Number for when it finally reaches Kevin Bacon.
Heres what the profesor is asking for this program: 1. Look up the actor relationship in your hashmap 2. Print the current relationship to the console 3.Call the method recursively with the second actor in the relationship(Make sure you increment your bacon number).
This method is confusing me and I'm having trouble completing it.
I need it to print something like this :
Helen Keller
Helen Keller starred in "Helen Keller in her story" with Katherine Cornell.
Katherine Cornell starred in " Stage Door Canteen " with Helen Hayes.
Helen Hays starred in "Murder with mirrors" with John Laughlin.
John Laughlin starred in " FootLoose" with Kevin Bacon.
The bacon number for Helen Keller is 4
If Anyone can help at all please do I really do need help