回答編集履歴
3
Scoreクラスも追加
answer
CHANGED
@@ -25,4 +25,28 @@
|
|
25
25
|
score.forEach(s -> System.out.printf("%s : Math : %d : English : %d\n", s.getName(), s.getMath(), s.getEnglish()));
|
26
26
|
}
|
27
27
|
}
|
28
|
+
|
29
|
+
class Score {
|
30
|
+
private String name;
|
31
|
+
private int math;
|
32
|
+
private int english;
|
33
|
+
|
34
|
+
public Score(String name, int math, int english) {
|
35
|
+
this.name = name;
|
36
|
+
this.math = math;
|
37
|
+
this.english = english;
|
38
|
+
}
|
39
|
+
|
40
|
+
public String getName() {
|
41
|
+
return name;
|
42
|
+
}
|
43
|
+
|
44
|
+
public int getMath() {
|
45
|
+
return math;
|
46
|
+
}
|
47
|
+
|
48
|
+
public int getEnglish() {
|
49
|
+
return english;
|
50
|
+
}
|
51
|
+
}
|
28
52
|
```
|
2
全部記述するように変更
answer
CHANGED
@@ -1,25 +1,28 @@
|
|
1
|
-
以下のインポートを追加しています。
|
2
1
|
```Java
|
3
2
|
import static java.util.Comparator.*;
|
4
|
-
```
|
5
3
|
|
6
|
-
```Java
|
7
|
-
|
4
|
+
import java.util.ArrayList;
|
8
5
|
|
6
|
+
public class SortScoreComparable {
|
9
|
-
|
7
|
+
public static void main(String[] args) {
|
10
|
-
score.add(new Score("jiro", 42, 54));
|
11
|
-
score.add(new Score("sabu", 42, 47));
|
12
|
-
score.add(new Score("siro", 57, 97));
|
13
|
-
score.add(new Score("goro", 87, 40));
|
14
|
-
score.add(new Score("roku", 99, 99));
|
15
|
-
score
|
8
|
+
ArrayList<Score> score = new ArrayList<Score>();
|
16
|
-
score.add(new Score("hati", 42, 54));
|
17
9
|
|
18
|
-
|
10
|
+
score.add(new Score("taro", 12, 97));
|
11
|
+
score.add(new Score("jiro", 42, 54));
|
12
|
+
score.add(new Score("sabu", 42, 47));
|
13
|
+
score.add(new Score("siro", 57, 97));
|
14
|
+
score.add(new Score("goro", 87, 40));
|
15
|
+
score.add(new Score("roku", 99, 99));
|
16
|
+
score.add(new Score("nana", 14, 23));
|
19
|
-
score.
|
17
|
+
score.add(new Score("hati", 42, 54));
|
20
18
|
|
19
|
+
System.out.println("ソート前");
|
21
|
-
score.
|
20
|
+
score.forEach(s -> System.out.printf("%s : Math : %d : English : %d\n", s.getName(), s.getMath(), s.getEnglish()));
|
22
21
|
|
22
|
+
score.sort(comparing(Score::getMath).thenComparing(Score::getEnglish).reversed());
|
23
|
+
|
23
|
-
System.out.println("ソート後");
|
24
|
+
System.out.println("ソート後");
|
24
|
-
score.forEach(s -> System.out.printf("%s : Math : %d : English : %d\n", s.getName(), s.getMath(), s.getEnglish()));
|
25
|
+
score.forEach(s -> System.out.printf("%s : Math : %d : English : %d\n", s.getName(), s.getMath(), s.getEnglish()));
|
26
|
+
}
|
27
|
+
}
|
25
28
|
```
|
1
追記
answer
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
+
以下のインポートを追加しています。
|
1
2
|
```Java
|
3
|
+
import static java.util.Comparator.*;
|
4
|
+
```
|
5
|
+
|
6
|
+
```Java
|
2
7
|
ArrayList<Score> score = new ArrayList<Score>();
|
3
8
|
|
4
9
|
score.add(new Score("taro", 12, 97));
|