-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatch.java
72 lines (61 loc) · 2.02 KB
/
Match.java
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
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class Match {
public static ArrayList<Students> students = new ArrayList<Students>();
private static int totalStudents = 0;
public static void main(String[] args) throws FileNotFoundException{
String file = "Students.txt";
Scanner input = new Scanner (new FileReader(file));
input.useDelimiter("[\t\r-]");
int test =0;
while (input.hasNextLine()){
String name = input.next();
char gender = input.next().charAt(0);
int month = input.nextInt();
int day = input.nextInt();
int year = input.nextInt();
int quiet = input.nextInt();
int music = input.nextInt();
int reading = input.nextInt();
int chatting = input.nextInt();
students.add(new Students(name,gender, new Date(month, day,year), new Preference(quiet, music, reading, chatting)));
//System.out.println(students.get(test).birthDay.dayOfYear() + " " + students.get(test).birthDay.getYear());
test++;
totalStudents++;
}
//System.out.println(students.get(9).compare(students.get(14)));
input.close();
int maxScore =0;
int current = 0;
int k=0;
int p;
for (int i = 0; i < students.size(); i++){
if(students.get(i).getMatch() == false){
maxScore =0;
current=0;
for(int j = i+1; j<students.size(); j++){
current = students.get(i).compare(students.get(j));
if(current == 0){
continue;
}
if(current > 0 && current > maxScore){
maxScore = current;
k=j;
}
}
if(students.get(i).getMatch() == false && students.get(k).getMatch() == false){
students.get(i).setMatch(true);
students.get(k).setMatch(true);
System.out.print(students.get(i).getName() + " matches with ");
System.out.println(students.get(k).getName() + " with score of " + maxScore);
//System.out.println(i);
//System.out.println(k);
}
else {
System.out.println(students.get(i).getName() + " has no match!");
}
}
}
}
}