ace

ShorterNameGenComplete

ace
Mar 17th, 2010
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.HashMap;
  3. /**
  4. * Write a description of class NameGenerator here.
  5. *
  6. * @author Jason
  7. * @version 1.0 3/17/10
  8.  
  9. /* class contains an array list for each of first names and second names
  10. *
  11. class contains a HashMap for names
  12. */
  13. public class NameGenerator
  14. {
  15.  
  16. private HashMap <String, String> nameMap;
  17.  
  18.  
  19.  
  20. /**
  21. * Constructor for objects of class NameGenerator
  22. */
  23. public NameGenerator()
  24. {
  25. /* creates an array list for first names;
  26. creates an array list for second names;
  27. creates a hash map for star wars names;
  28. */
  29. nameMap = new HashMap <String, String>();
  30.  
  31. }
  32.  
  33. /**
  34. * method to generate first star wars name
  35. */
  36. public String generateStarWarsName(String firstName, String secondName, String mothersName,
  37. String townName)
  38. {
  39.  
  40. String firstSWName = secondName.substring(0, 3) + firstName.substring(0,2);
  41. String secondSWName = (mothersName.substring(0,2) + townName.substring(0,3));
  42. String starWarsName = firstSWName + " " + secondSWName;
  43. nameMap.put(firstSWName, starWarsName);
  44. nameMap.put(secondSWName, starWarsName);
  45. return starWarsName;
  46.  
  47. }
  48. }
Add Comment
Please, Sign In to add comment