Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

ShorterNameGenComplete

By: ace on Mar 17th, 2010  |  syntax: None  |  size: 1.31 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }