回答編集履歴

3

Scoreクラスも追加

2017/09/27 07:43

投稿

root_jp
root_jp

スコア4666

test CHANGED
@@ -52,4 +52,52 @@
52
52
 
53
53
  }
54
54
 
55
+
56
+
57
+ class Score {
58
+
59
+ private String name;
60
+
61
+ private int math;
62
+
63
+ private int english;
64
+
65
+
66
+
67
+ public Score(String name, int math, int english) {
68
+
69
+ this.name = name;
70
+
71
+ this.math = math;
72
+
73
+ this.english = english;
74
+
75
+ }
76
+
77
+
78
+
79
+ public String getName() {
80
+
81
+ return name;
82
+
83
+ }
84
+
85
+
86
+
87
+ public int getMath() {
88
+
89
+ return math;
90
+
91
+ }
92
+
93
+
94
+
95
+ public int getEnglish() {
96
+
97
+ return english;
98
+
99
+ }
100
+
101
+ }
102
+
55
103
  ```

2

全部記述するように変更

2017/09/27 07:43

投稿

root_jp
root_jp

スコア4666

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

1

追記

2017/09/27 07:34

投稿

root_jp
root_jp

スコア4666

test CHANGED
@@ -1,3 +1,13 @@
1
+ 以下のインポートを追加しています。
2
+
3
+ ```Java
4
+
5
+ import static java.util.Comparator.*;
6
+
7
+ ```
8
+
9
+
10
+
1
11
  ```Java
2
12
 
3
13
  ArrayList<Score> score = new ArrayList<Score>();