Mattie

Untitled

Oct 6th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.04 KB | None | 0 0
  1. package opdrachtB_2;
  2.  
  3. import java.util.*;
  4.  
  5. public class SillySentense
  6. {
  7.  
  8.     private HashMap<String, HashMap<Integer, String>> sentencesMap = new HashMap<String, HashMap<Integer, String>>();
  9.     private Random random = new Random();;
  10.  
  11.     public SillySentense()
  12.     {
  13.  
  14.     }
  15.  
  16.     public void fillSentence()
  17.     {
  18.         HashMap<Integer, String> map = new HashMap<Integer, String>();
  19.  
  20.         map.put(0, "#PERSON$ #DOES$ #SOMETHING$");
  21.         map.put(1, "#PERSON$ thinks that I am #PROPERTY$");
  22.         map.put(2, "I #DO$ #SOMETHING$");
  23.         map.put(3, "you think that I am #PROPERTY$");
  24.  
  25.         sentencesMap.put("SENTENCE", map);
  26.     }
  27.  
  28.     public void fillActivity()
  29.     {
  30.         HashMap<Integer, String> map = new HashMap<Integer, String>();
  31.  
  32.         map.put(0, "dancing");
  33.         map.put(1, "eating");
  34.         map.put(2, "sleeping");
  35.  
  36.         sentencesMap.put("ACTIVITY", map);
  37.     }
  38.  
  39.     public void fillObject()
  40.     {
  41.         HashMap<Integer, String> map = new HashMap<Integer, String>();
  42.  
  43.         map.put(0, "#PERSOM$");
  44.         map.put(1, "my computer");
  45.         map.put(2, "my friends");
  46.  
  47.         sentencesMap.put("OBJECT", map);
  48.     }
  49.  
  50.     public void fillDo()
  51.     {
  52.         HashMap<Integer, String> map = new HashMap<Integer, String>();
  53.  
  54.         map.put(0, "hate");
  55.         map.put(1, "am jealous of");
  56.         map.put(2, "love");
  57.  
  58.         sentencesMap.put("DO", map);
  59.     }
  60.  
  61.     public void fillDoes()
  62.     {
  63.         HashMap<Integer, String> map = new HashMap<Integer, String>();
  64.  
  65.         map.put(0, "hates");
  66.         map.put(1, "loves");
  67.  
  68.         sentencesMap.put("DOES", map);
  69.     }
  70.  
  71.     public void fillPerson()
  72.     {
  73.         HashMap<Integer, String> map = new HashMap<Integer, String>();
  74.  
  75.         map.put(0, "my sister");
  76.         map.put(1, "my father");
  77.         map.put(2, "my girlgriend");
  78.         map.put(3, "the man next door");
  79.  
  80.         sentencesMap.put("PERSON", map);
  81.     }
  82.  
  83.     public void fillProperty()
  84.     {
  85.         HashMap<Integer, String> map = new HashMap<Integer, String>();
  86.  
  87.         map.put(0, "creative");
  88.         map.put(1, "intelligent");
  89.  
  90.         sentencesMap.put("PROPERTY", map);
  91.     }
  92.  
  93.     public void fillSomething()
  94.     {
  95.         HashMap<Integer, String> map = new HashMap<Integer, String>();
  96.  
  97.         map.put(0, "#ACTIVITY$");
  98.         map.put(1, "#ACTIVITY$ with #PERSON$");
  99.         map.put(2, "#OBJECT$");
  100.  
  101.         sentencesMap.put("SOMETHING", map);
  102.     }
  103.  
  104.     public void fillItAll()
  105.     {
  106.         fillSentence();
  107.         fillActivity();
  108.         fillDo();
  109.         fillDoes();
  110.         fillObject();
  111.         fillPerson();
  112.         fillProperty();
  113.         fillSomething();
  114.     }
  115.  
  116.     @SuppressWarnings("rawtypes")
  117.     public void print(int number)
  118.     {
  119.         for (int bla = 0; bla < number; bla++)
  120.         {
  121.  
  122.             Map m = sentencesMap.get("SENTENCE");
  123.             // m.toString();
  124.  
  125.             int r = random.nextInt(3);
  126.             // System.out.println(r);
  127.  
  128.             String sentence = (String) m.get(r);
  129.  
  130.             String[] sentences = sentence.split(" ");
  131.  
  132.             String zin = "";
  133.  
  134.             for (int i = 0; i < sentences.length; i++)
  135.             {
  136.                 String woord = sentences[i];
  137.                 // System.out.println(woord);
  138.  
  139.                 if (woord.startsWith("#") && woord.endsWith("$")) // het is eenv ariable
  140.                 {
  141.                     woord = woord.substring(1, woord.length() - 1);// # en $ weghalen
  142.                     // System.out.println(woord);
  143.  
  144.                     Map activity = sentencesMap.get(woord);
  145.                     int r2 = random.nextInt(activity.size() - 1);
  146.                     woord = (String) activity.get(r2);
  147.                     if (woord.startsWith("#") && woord.endsWith("$"))
  148.                     {
  149.                         // System.out.println(woord);
  150.                         woord = woord.substring(1, woord.length() - 1);// # en $ weghalen
  151.                         Map activity2 = sentencesMap.get(woord);
  152.                         int r3 = random.nextInt(activity2.size() - 1);
  153.                         woord = (String) activity2.get(r3);
  154.                     }
  155.                     // System.out.println("2" + woord);
  156.                 }
  157.  
  158.                 zin = zin + " " + woord;
  159.             }
  160.  
  161.             System.out.println(zin.trim());
  162.  
  163.             // for (int i = 0; i < m.size(); i++)
  164.             // {
  165.             //
  166.             // }
  167.         }
  168.     }
  169.  
  170.     public void z(String s)
  171.     {
  172.         System.out.println(s);
  173.     }
  174.  
  175.     @SuppressWarnings("rawtypes")
  176.     public void printALL()
  177.     {
  178.         for (String key : sentencesMap.keySet())
  179.         {
  180.             Map m = sentencesMap.get(key);
  181.             String bla = (String) key;
  182.  
  183.             for (int i = 0; i < m.size(); i++)
  184.             {
  185.                 String woord = (String) m.get(i);
  186.                 System.out.println(bla + " : " + woord);
  187.             }
  188.         }
  189.     }
  190.  
  191.     public void random()
  192.     {
  193.  
  194.     }
  195.  
  196. }
  197.  
  198.  
Advertisement
Add Comment
Please, Sign In to add comment