Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Cocktail
  4. {
  5.  
  6. private int aSpirit;
  7. public static String inputChoice()
  8. {
  9. // create a list of Integer type
  10. List<Integer> list = new ArrayList<>();
  11. // add 4 element in ArrayList
  12. list.add(1);
  13. list.add(2);
  14. list.add(3);
  15. list.add(4);
  16.  
  17. Cocktail spirit = new Cocktail();
  18. // take a random element from list and print them
  19. int aSpirit = spirit.getRandomElement(list);
  20. if (aSpirit == 1)
  21. {
  22. return ("Vodka");
  23. }
  24. else if (aSpirit == 2)
  25. {
  26. return ("Rum");
  27. }
  28. else if (aSpirit == 3)
  29. {
  30. return ("Gin");
  31. }
  32. else
  33. {
  34. return ("Other");
  35. }
  36. }
  37.  
  38. // Function select an element base on index
  39. // and return an element
  40. public int getRandomElement(List<Integer> list)
  41. {
  42. Random rand = new Random();
  43. return list.get(rand.nextInt(list.size()));
  44. }
  45.  
  46. public void addMapEntry()
  47. {
  48. Map<String, Set<String>> cocktailMap = new HashMap<>();
  49. Set<String> ingredients = new HashSet<>();
  50.  
  51. ingredients.add("Vodka");
  52. ingredients.add("Gin");
  53. ingredients.add("Tequila");
  54. ingredients.add("Rum");
  55. ingredients.add("Triple Sec");
  56. cocktailMap.put("LIIT", ingredients);
  57.  
  58. ingredients.add("Rum");
  59. cocktailMap.put("Mojito", ingredients);
  60.  
  61. ingredients.add("Gin");
  62. ingredients.add("Creme de Mure");
  63. cocktailMap.put("Bramble", ingredients);
  64.  
  65. ingredients.add("Vodka");
  66. cocktailMap.put("Martini", ingredients);
  67.  
  68. // Set<String> randomCocktail = aSpirit;
  69. String stringOut;
  70. Set<String> eachCocktail;
  71. Set<String> cross;
  72.  
  73. for (String aCocktail : cocktailMap.keySet())
  74. {
  75. eachCocktail = cocktailMap.get(aCocktail);
  76. cross = new HashSet<>(aSpirit);
  77. cross.retainAll(eachCocktail);
  78. stringOut = "The " + aSpirit + " cocktails are " + eachCocktail;
  79. System.out.println(stringOut);
  80. }
  81.  
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement