Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Cocktail
- {
- private int aSpirit;
- public static String inputChoice()
- {
- // create a list of Integer type
- List<Integer> list = new ArrayList<>();
- // add 4 element in ArrayList
- list.add(1);
- list.add(2);
- list.add(3);
- list.add(4);
- Cocktail spirit = new Cocktail();
- // take a random element from list and print them
- int aSpirit = spirit.getRandomElement(list);
- if (aSpirit == 1)
- {
- return ("Vodka");
- }
- else if (aSpirit == 2)
- {
- return ("Rum");
- }
- else if (aSpirit == 3)
- {
- return ("Gin");
- }
- else
- {
- return ("Other");
- }
- }
- // Function select an element base on index
- // and return an element
- public int getRandomElement(List<Integer> list)
- {
- Random rand = new Random();
- return list.get(rand.nextInt(list.size()));
- }
- public void addMapEntry()
- {
- Map<String, Set<String>> cocktailMap = new HashMap<>();
- Set<String> ingredients = new HashSet<>();
- ingredients.add("Vodka");
- ingredients.add("Gin");
- ingredients.add("Tequila");
- ingredients.add("Rum");
- ingredients.add("Triple Sec");
- cocktailMap.put("LIIT", ingredients);
- ingredients.add("Rum");
- cocktailMap.put("Mojito", ingredients);
- ingredients.add("Gin");
- ingredients.add("Creme de Mure");
- cocktailMap.put("Bramble", ingredients);
- ingredients.add("Vodka");
- cocktailMap.put("Martini", ingredients);
- // Set<String> randomCocktail = aSpirit;
- String stringOut;
- Set<String> eachCocktail;
- Set<String> cross;
- for (String aCocktail : cocktailMap.keySet())
- {
- eachCocktail = cocktailMap.get(aCocktail);
- cross = new HashSet<>(aSpirit);
- cross.retainAll(eachCocktail);
- stringOut = "The " + aSpirit + " cocktails are " + eachCocktail;
- System.out.println(stringOut);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement