回答編集履歴
1
コード追加
test
CHANGED
@@ -1 +1,71 @@
|
|
1
1
|
alignX/Y は座標値を直接指定せず, Turtle で指定します. ですので, 別途 Turtle を生成して座標を設定し, 各Turtle の設定に使用しては如何でしょうか.
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
```java
|
6
|
+
|
7
|
+
double sum = turtles[0].getY();
|
8
|
+
|
9
|
+
Turtle max = turtles[0];//最大候補
|
10
|
+
|
11
|
+
Turtle min = turtles[0];//最小候補
|
12
|
+
|
13
|
+
for(int i = 1; i < n; i++) {
|
14
|
+
|
15
|
+
sum += turtles[i].getY();
|
16
|
+
|
17
|
+
if(turtles[i].getX() > max.getX()) {
|
18
|
+
|
19
|
+
max = turtles[i];//最大値候補を更新
|
20
|
+
|
21
|
+
System.out.println("maxBeta : "+ max.getX() +", idxMax : "+ i);
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
if(turtles[i].getX() < min.getX()) {
|
26
|
+
|
27
|
+
min = turtles[i];//最小値候補を更新
|
28
|
+
|
29
|
+
System.out.println("minBeta : "+ min.getX() +", idxMin : "+ i);
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
Turtle ave = new Turtle(0,sum/n,0.0); // yのみ使用する
|
36
|
+
|
37
|
+
System.out.println("Y座標の合計:"+ sum);
|
38
|
+
|
39
|
+
System.out.println("Y座標の平均:"+ ave.getY());
|
40
|
+
|
41
|
+
System.out.println("X座標のmax : "+ max.getX() +", min : "+ min.getX());
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
for(int i = 0; i < n; i ++) {
|
46
|
+
|
47
|
+
System.out.println();
|
48
|
+
|
49
|
+
if(i % 2 == 0) {
|
50
|
+
|
51
|
+
System.out.println("偶数");
|
52
|
+
|
53
|
+
alignX(max, turtles[i]);
|
54
|
+
|
55
|
+
}else{
|
56
|
+
|
57
|
+
System.out.println("奇数 : ");
|
58
|
+
|
59
|
+
alignX(min, turtles[i]);
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
alignY(ave, turtles[i]);
|
64
|
+
|
65
|
+
System.out.println("i : " + i);
|
66
|
+
|
67
|
+
System.out.println(i + "の x, y座標 = " + turtles[i].getX() + ", "+ turtles[i].getY());
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
```
|