質問編集履歴
1
コードを大きく変更しなおしたので、更新しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,15 +6,13 @@
|
|
6
6
|
|
7
7
|
import java.nio.file.*;
|
8
8
|
|
9
|
+
import readData.*;
|
10
|
+
|
9
11
|
|
10
12
|
|
11
13
|
public class readAndWrite {
|
12
14
|
|
13
|
-
readData rd;
|
14
|
-
|
15
|
-
readDataBook rdbook
|
15
|
+
public void read(readData rd, readDataBook rdbook) {
|
16
|
-
|
17
|
-
public read() {
|
18
16
|
|
19
17
|
try(FileReader fr = new FileReader("data.csv")) {
|
20
18
|
|
@@ -26,7 +24,11 @@
|
|
26
24
|
|
27
25
|
while (line != null) {
|
28
26
|
|
27
|
+
System.out.println(line);
|
28
|
+
|
29
|
-
rd
|
29
|
+
rd.setReadData(line);
|
30
|
+
|
31
|
+
rdbook.addReadDataBook(rd);
|
30
32
|
|
31
33
|
line = reader.readLine();
|
32
34
|
|
@@ -46,8 +48,56 @@
|
|
46
48
|
|
47
49
|
|
48
50
|
|
51
|
+
public void write(int num, readDataBook book) {
|
52
|
+
|
53
|
+
try (PrintWriter w = new PrintWriter(
|
54
|
+
|
55
|
+
new BufferedWriter(
|
56
|
+
|
57
|
+
new FileWriter("out.txt")))) {
|
58
|
+
|
59
|
+
//各教科の平均点を書き出す
|
60
|
+
|
61
|
+
w.println(book.japaneseAverage());
|
62
|
+
|
63
|
+
w.println(book.mathAverage());
|
64
|
+
|
65
|
+
w.println(book.englishAverage());
|
66
|
+
|
67
|
+
w.println(book.scienceAverage());
|
68
|
+
|
69
|
+
w.println(book.socialAverage());
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
//5教科平均点を書き出す
|
74
|
+
|
75
|
+
w.println(book.fiveAverage());
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
//5教科合計の1位を書き出す
|
80
|
+
|
81
|
+
w.println("1位 " + book.fiveWinPerson() + " " + book.fiveWinScore());
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
} catch(IOException e) {
|
88
|
+
|
89
|
+
System.out.println(e);
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
49
97
|
}
|
50
98
|
|
99
|
+
|
100
|
+
|
51
101
|
```
|
52
102
|
|
53
103
|
|
@@ -76,7 +126,7 @@
|
|
76
126
|
|
77
127
|
|
78
128
|
|
79
|
-
public
|
129
|
+
public void setReadData(String n, int j, int m, int e, int sc, int so) {
|
80
130
|
|
81
131
|
this.name = n;
|
82
132
|
|
@@ -142,7 +192,7 @@
|
|
142
192
|
|
143
193
|
|
144
194
|
|
145
|
-
public int
|
195
|
+
public int getSum() {
|
146
196
|
|
147
197
|
int sum;
|
148
198
|
|
@@ -154,13 +204,13 @@
|
|
154
204
|
|
155
205
|
|
156
206
|
|
157
|
-
public
|
207
|
+
public double getAverage() {
|
158
208
|
|
159
209
|
int sum;
|
160
210
|
|
161
211
|
double ave;
|
162
212
|
|
163
|
-
sum = this.
|
213
|
+
sum = this.getSum();
|
164
214
|
|
165
215
|
ave = (double)sum / 5;
|
166
216
|
|
@@ -188,7 +238,9 @@
|
|
188
238
|
|
189
239
|
|
190
240
|
|
241
|
+
//読み込んだデータを配列に格納する
|
242
|
+
|
191
|
-
public addReadDataBook(readData r) {
|
243
|
+
public void addReadDataBook(readData r) {
|
192
244
|
|
193
245
|
list[num] = r;
|
194
246
|
|
@@ -196,7 +248,17 @@
|
|
196
248
|
|
197
249
|
}
|
198
250
|
|
199
|
-
|
251
|
+
//何人分のデータが格納されているかを返す
|
252
|
+
|
253
|
+
public int getNum() {
|
254
|
+
|
255
|
+
return this.num;
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
//各教科の平均点を返す
|
200
262
|
|
201
263
|
public double japaneseAverage() {
|
202
264
|
|
@@ -206,7 +268,7 @@
|
|
206
268
|
|
207
269
|
for(int i=0; i<num; i++) {
|
208
270
|
|
209
|
-
sum += list[i].getJapanese;
|
271
|
+
sum += list[i].getJapanese();
|
210
272
|
|
211
273
|
}
|
212
274
|
|
@@ -224,7 +286,7 @@
|
|
224
286
|
|
225
287
|
for(int i=0; i<num; i++) {
|
226
288
|
|
227
|
-
sum += list[i].getMath;
|
289
|
+
sum += list[i].getMath();
|
228
290
|
|
229
291
|
}
|
230
292
|
|
@@ -242,7 +304,7 @@
|
|
242
304
|
|
243
305
|
for(int i=0; i<num; i++) {
|
244
306
|
|
245
|
-
sum += list[i].getEnglish;
|
307
|
+
sum += list[i].getEnglish();
|
246
308
|
|
247
309
|
}
|
248
310
|
|
@@ -260,7 +322,7 @@
|
|
260
322
|
|
261
323
|
for(int i=0; i<num; i++) {
|
262
324
|
|
263
|
-
sum += list[i].getScience;
|
325
|
+
sum += list[i].getScience();
|
264
326
|
|
265
327
|
}
|
266
328
|
|
@@ -278,7 +340,7 @@
|
|
278
340
|
|
279
341
|
for(int i=0; i<num; i++) {
|
280
342
|
|
281
|
-
sum += list[i].getSocial;
|
343
|
+
sum += list[i].getSocial();
|
282
344
|
|
283
345
|
}
|
284
346
|
|
@@ -288,23 +350,93 @@
|
|
288
350
|
|
289
351
|
|
290
352
|
|
353
|
+
//5教科の平均点を返す
|
354
|
+
|
355
|
+
public double fiveAverage() {
|
356
|
+
|
357
|
+
int sum = 0;
|
358
|
+
|
359
|
+
double fiveave;
|
360
|
+
|
361
|
+
for(int i=0; i<num; i++) {
|
362
|
+
|
363
|
+
sum += list[i].getSum();
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
fiveave = (double)sum / num;
|
368
|
+
|
369
|
+
return fiveave;
|
370
|
+
|
371
|
+
}
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
//5教科の1位の人を返す
|
376
|
+
|
377
|
+
public String fiveWinPerson() {
|
378
|
+
|
379
|
+
int winner = 0, rt = 0;
|
380
|
+
|
381
|
+
for(int i=0; i<num; i++) {
|
382
|
+
|
383
|
+
if(winner < list[i].getSum()) {
|
384
|
+
|
385
|
+
winner = list[i].getSum();
|
386
|
+
|
387
|
+
rt = i;
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
return list[rt].name;
|
394
|
+
|
395
|
+
}
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
//5教科の1位の得点を返す
|
400
|
+
|
401
|
+
public int fiveWinScore() {
|
402
|
+
|
403
|
+
int winner = 0, rt = 0;
|
404
|
+
|
405
|
+
for(int i=0; i<num; i++) {
|
406
|
+
|
407
|
+
if(winner < list[i].getSum()) {
|
408
|
+
|
409
|
+
winner = list[i].getSum();
|
410
|
+
|
411
|
+
rt = i;
|
412
|
+
|
413
|
+
}
|
414
|
+
|
415
|
+
}
|
416
|
+
|
417
|
+
return list[rt].getSum();
|
418
|
+
|
419
|
+
}
|
420
|
+
|
421
|
+
|
422
|
+
|
291
423
|
}
|
292
424
|
|
293
425
|
```
|
294
426
|
|
295
427
|
```csv
|
296
428
|
|
297
|
-
masaki
|
429
|
+
masaki,86,75,94,73,83
|
298
|
-
|
430
|
+
|
299
|
-
nobuyuki
|
431
|
+
nobuyuki,91,89,96,88,94
|
300
|
-
|
432
|
+
|
301
|
-
hironobu
|
433
|
+
hironobu,60,54,36,59,43
|
302
|
-
|
434
|
+
|
303
|
-
syuji
|
435
|
+
syuji,71,68,69,71,71
|
304
|
-
|
436
|
+
|
305
|
-
masayasu
|
437
|
+
masayasu,42,31,56,42,38
|
306
|
-
|
438
|
+
|
307
|
-
toshiaki
|
439
|
+
toshiaki,66,57,63,59,68
|
308
440
|
|
309
441
|
```
|
310
442
|
|
@@ -316,6 +448,26 @@
|
|
316
448
|
|
317
449
|
|
318
450
|
|
319
|
-
###
|
451
|
+
### 発生しているエラー
|
452
|
+
|
320
|
-
|
453
|
+
./readAndWrite.java:14: エラー: クラス readDataのメソッド setReadDataは指定された型に適用できません。
|
454
|
+
|
455
|
+
rd.setReadData(line);
|
456
|
+
|
457
|
+
^
|
458
|
+
|
459
|
+
期待値: String,int,int,int,int,int
|
460
|
+
|
461
|
+
検出値: String
|
462
|
+
|
463
|
+
理由: 実引数リストと仮引数リストの長さが異なります
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
__エラー解釈__
|
468
|
+
|
469
|
+
変数lineをString型で定義しているため、引数がint型であるsetReadDataを正しく使用できていない。
|
470
|
+
|
471
|
+
|
472
|
+
|
321
|
-
|
473
|
+
ネットで調べたのですが、どのようにStringをintに変換してうまく読み込ませればよいのかわからなかったので教えてください。
|