-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSSLogic.java
More file actions
78 lines (56 loc) · 2.33 KB
/
SSLogic.java
File metadata and controls
78 lines (56 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.util.*;
public class SSLogic {
public static void main(String[] args){
boolean goCond = true;
Scanner sc = new Scanner(System.in);
ArrayList<SSPerson> allPersons = new ArrayList<SSPerson>();
int i = -1;
// Entering names into the list
while(goCond){
System.out.print("\nEnter name: ");
allPersons.add(new SSPerson(sc.nextLine()));
boolean secGoCond = false;
i++;
System.out.print("Enter items to your wishlist? (Yes or No): ");
if(sc.nextLine().toUpperCase().equals("YES")) secGoCond = true;
else secGoCond = false;
System.out.println();
while(secGoCond){
System.out.print("Enter the item you want: ");
allPersons.get(i).addWish(sc.nextLine());
System.out.print("Would you like to add more wishes?: (Yes or No) ");
if(sc.nextLine().toUpperCase().equals("NO")) secGoCond = false;
}
System.out.println();
for(int j = 0; j < allPersons.size(); j++){
System.out.println(allPersons.get(j));
}
System.out.print("Any more people to add? (Yes or No) ");
if(sc.nextLine().toUpperCase().equals("NO")) goCond = false;
}
// Randomizing and assigning secret santa people
System.out.println("\nFinal list");
for(int j = 0; j < allPersons.size(); j++){
System.out.println(allPersons.get(j));
}
// randomize section
ArrayList<Integer> randIndex = new ArrayList<Integer>();
for(int j = 0; j < allPersons.size(); j++){
randIndex.add(j);
}
Collections.shuffle(randIndex);
for(int j = 0; j < randIndex.size(); j++){
while(j == randIndex.get(j)){
Collections.shuffle(randIndex);
j = 0;
}
}
for(int j = 0; j < allPersons.size(); j++){
allPersons.get(j).assignPerson(allPersons.get(randIndex.get(j)));
}
System.out.println();
for(int j = 0; j < allPersons.size(); j++){
System.out.println(allPersons.get(j));
}
}
}