-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuiz.java
More file actions
44 lines (41 loc) · 1.22 KB
/
Quiz.java
File metadata and controls
44 lines (41 loc) · 1.22 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
import java.util.*;
public class Quiz {
private ArrayList<Question> questions;
public ArrayList<SelectionGroup> groups;
public Quiz(ArrayList<Question> q, ArrayList<SelectionGroup> g){
questions = q;
Collections.shuffle(questions);
groups = g;
}
public void startQuiz(){
for(int i = 0;i < question.size(); i++){
displayQuestion(questions[i]);//not implemented
}
//game finished
sortGroupsByScore(groups);
for(int i = 0;i < groups.size(); i++){
System.out.print("Group number " + (i+1) + " is " + groups[i].name + " with " + groups[i].score + " !");
}
//not implemented
}
//sorts group by highest to lowest score
public ArrayList<SelectionGroup> sortGroupsByScore(ArrayList<SelectionGroup> g){
ArrayList<SelectionGroup> temp = new ArrayList<SelectionGroup>();
int s = groups.size();
while(temp.size < s){
int greatestScore = Integer.MIN_VALUE;
SelectionGroup group;
int index = 0;
for(int i = 0; i < g.size(); i++){
if(g[i].score > greatestScore){
group = g[i];
greatestScore = g[i].score;
index = i;
}
}
temp.add(group);
g.remove(index);
}
}
return temp;
}