Repository navigation
Expand file tree
/
Copy pathScore.java
More file actions
85 lines (55 loc) · 1.73 KB
/
Copy pathScore.java
File metadata and controls
85 lines (55 loc) · 1.73 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
79
80
81
82
83
84
85
import java.io.*;
import java.util.*;
class Score{
public void writeScore(String pName,String gName,Integer pScore){
BufferedWriter bWrite=null;
String s="Score"+pName+".txt";
try {
bWrite =new BufferedWriter(new FileWriter(s,true));
if(pScore<10)
bWrite.append(pName+" "+gName+" "+'0'+pScore);
else
bWrite.append(pName+" "+gName+" "+pScore);
bWrite.newLine();
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
bWrite.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public List readScore(String pName){
Comparator<String> mComp=new scoreComparator();
List<String> uScore=new ArrayList<String>();
int lineNo;
String line;
String k="Score"+pName+".txt";
try {
FileReader fr = new FileReader(k);
BufferedReader br = new BufferedReader(fr);
for (lineNo = 0; lineNo < 10; lineNo++) {
line=br.readLine();
uScore.add(line);
}
Collections.sort(uScore,mComp);
} catch (Exception e) {
e.printStackTrace();
}
return uScore;
}
}
class scoreComparator implements Comparator<String>{
@Override
public int compare(String a, String b){
try{
if(a.compareTo(b)<0)
return -1;
}
catch(Exception e){
}
return 0;
}
}