One of the more popular holiday games, Secret Santa (also known as Kris Kringle in some circles) is a fun and easy way for a group of friends, family members or co-workers to exchange gifts.
The basic concept of the Secret Santa game is simple. All of the participants’ names are placed into a hat, box, etc. and mixed up. Each person then chooses one name from the box, but doesn't tell anyone which name was picked. He/she is now responsible for buying a gift for the person selected.
For more information how to play? Click me!! and to play online Click me!!
Today we will explore concepts of Collections in Java to create Virtual name drawing Program.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Scanner; | |
import java.util.TreeMap; | |
public class LogicalClass { | |
//results are saved in map | |
static Map<Integer,Integer> mappings=new TreeMap<Integer,Integer>(); | |
static List<Integer> listNumbers1=new ArrayList<Integer>(); | |
static List<Integer> listNumbers2=new ArrayList<Integer>(); | |
public static void match(){ | |
//taking input from users. | |
System.out.println("enter the number of players"); | |
Scanner sc=new Scanner(System.in); | |
int players=sc.nextInt(); | |
for(int i=0;i<players;i++){ | |
listNumbers.add(i+1); | |
listNumbe.add(i+1); | |
} | |
// shuffle mehtod using to randomize the elements in list. | |
Collections.shuffle(listNumbers); | |
Collections.shuffle(listNumbe); | |
for(int i=0;i<players;i++){ | |
mappings.put(listNumbers.get(i),listNumbe.get((players-1)-i)); | |
} | |
for(Map.Entry<Integer,Integer> entry : mappings.entrySet()) { | |
System.out.println(entry.getKey()+"should be secret santa for "+entry.getValue()); | |
} | |
sc.close(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ClientCkass { | |
public static void main(String[] args) { | |
// calling static match method of class Logical class from Client class(main) class | |
LogicalClass.match(); | |
} | |
} |
How to use this code to draw the names??! Well it is simple all you need to do is
- take a Notepad/Notepad++, write down the names of the players.
- copy pass the code in two classes and run the program.
- compare the results with the names written in the notepad(by default Notepad++ has number displayed for each line which makes your job easy to compare results).
As reported by Stanford Medical, It is in fact the one and ONLY reason women in this country get to live 10 years more and weigh 19 KG lighter than we do.
ReplyDelete(Just so you know, it has NOTHING to do with genetics or some secret-exercise and really, EVERYTHING to do with "how" they eat.)
BTW, I said "HOW", and not "what"...
CLICK this link to uncover if this easy test can help you release your true weight loss possibility