質問編集履歴
2
配列の要素数について
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
javaで
|
1
|
+
javaでのオブジェクト指向について
|
body
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
```
|
2
|
-
|
2
|
+
オブジェクト指向について
|
3
3
|
配列の要素数をある数以上にしようとするとエラー
|
1
配列の要素数について
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,135 +1,3 @@
|
|
1
|
-
###前提・実現したいこと
|
2
|
-
java初心者です。
|
3
|
-
javaでcsvファイルを読み込み、以下の処理結果を別ファイルに出力するシステムを作ることに挑戦しています。
|
4
|
-
|
5
|
-
*読み込みデータ例
|
6
|
-
佐藤,a,80,56,78,98,76
|
7
|
-
田中,b,45,67,87,87,89
|
8
|
-
鈴木,c,89,67,79,76,56
|
9
|
-
高橋,d,76,87,98,78,98
|
10
|
-
|
11
|
-
*出力結果例
|
12
|
-
佐藤,77.6,平均
|
13
|
-
田中,89,最高点
|
14
|
-
鈴木,84,中間点(最高点と最低点の平均)
|
15
|
-
高橋,87,点数を降順に並べた中心点
|
16
|
-
|
17
|
-
条件としては、一つクラスを作って(studentクラス)、そのクラスで名前、条件アルファベット、点数5つを格納して、そのクラスをメインメソッドで呼び出すことなのですが、ファイル出入力、例外処理の部分はなんとかコーディングできたのですが、クラスをうまくメインメソッドで利用できず困っています。
|
18
|
-
添削していただけないでしょうか。どうぞよろしくお願いします。
|
19
1
|
```
|
20
|
-
エラーメッセージ
|
21
|
-
```
|
22
2
|
|
23
|
-
###該当のソースコード
|
24
|
-
import java.io.*;
|
25
|
-
//ファイル入出力
|
26
|
-
public class Syutsuryoku {
|
27
|
-
private final static String inputCsvFile = "abc.csv";
|
28
|
-
private final static String outputCsvFile = "def.csv";
|
29
|
-
public static void main(String[] args){
|
30
|
-
String line;
|
31
|
-
String[] csvArray;
|
32
|
-
File inputFile = new File(inputCsvFile);
|
33
|
-
File outputFile = new File(outputCsvFile);
|
34
|
-
BufferedReader in = null;
|
35
|
-
BufferedWriter out = null;
|
36
|
-
try {
|
37
|
-
in = new BufferedReader(new FileReader(inputFile));
|
38
|
-
out = new BufferedWriter(new FileWriter(outputFile));
|
39
|
-
|
40
|
-
while ((line = in.readLine()) != null){
|
41
|
-
csvArray = line.split("\\,");
|
42
|
-
for(int i=0; i < csvArray.length ; i++){
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}
|
46
|
-
}
|
47
|
-
catch(FileNotFoundException e){
|
48
|
-
e.printStackTrace();
|
49
|
-
}catch(IOException e){
|
50
|
-
e.printStackTrace();
|
51
|
-
}finally{
|
52
|
-
try{
|
53
|
-
if (in != null){
|
54
|
-
in.close();
|
55
|
-
}
|
56
|
-
if(out != null){
|
57
|
-
out.close();
|
58
|
-
}
|
59
|
-
}catch(IOException e){
|
60
|
-
e.printStackTrace();
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
}
|
65
|
-
|
66
|
-
}
|
67
|
-
//studentクラス
|
68
|
-
class Student {
|
69
|
-
String name;
|
70
|
-
String calc;
|
71
|
-
int scores = new int[5];
|
72
|
-
int max;
|
73
|
-
int min;
|
74
|
-
|
3
|
+
配列の要素数をある数以上にしようとするとエラー
|
75
|
-
int average(int[] a){
|
76
|
-
int sum = 0;
|
77
|
-
for(int i=0; i<a.length; i++){
|
78
|
-
sum += a[i];
|
79
|
-
}
|
80
|
-
return sum / a.length;
|
81
|
-
}
|
82
|
-
//最高点を得るメソッド
|
83
|
-
int maxNumber(int[] a){
|
84
|
-
int max = a[0];
|
85
|
-
for (int i = 1; i < a.length; i++) {
|
86
|
-
if (max < a[i]) {
|
87
|
-
max = a[i];
|
88
|
-
}
|
89
|
-
}
|
90
|
-
return max;
|
91
|
-
}
|
92
|
-
//最低点を得るメソッド
|
93
|
-
int minNumber(int[] a){
|
94
|
-
int min = a[0];
|
95
|
-
for(int i = 1; i < a.length; i++) {
|
96
|
-
if (a[i] < min) {
|
97
|
-
min = a[i];
|
98
|
-
}
|
99
|
-
}
|
100
|
-
return min;
|
101
|
-
}
|
102
|
-
//最低点と最高点の平均を算出するメソッド
|
103
|
-
int extremeAverage(int[] a){
|
104
|
-
int exAve = (this.max + this.min) / 2;
|
105
|
-
return exAve;
|
106
|
-
}
|
107
|
-
//中心値を得るメソッド
|
108
|
-
int desNumber(int[] a){
|
109
|
-
for(int i = 0; i < a.length-1; i++){
|
110
|
-
for(int j = i+1; j < a.length; j++){
|
111
|
-
if(a[j] > a[i]){
|
112
|
-
int des = a[i];
|
113
|
-
a[i] = a[j];
|
114
|
-
a[j] = des;
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
switch (a.length % 2) {
|
119
|
-
case 0:
|
120
|
-
a[j] = a[(a.length / 2)+1];
|
121
|
-
break;
|
122
|
-
case 1:
|
123
|
-
a[j] = a[a.length / 2];
|
124
|
-
break;
|
125
|
-
}
|
126
|
-
}
|
127
|
-
return a[j];
|
128
|
-
}
|
129
|
-
}
|
130
|
-
|
131
|
-
###試したこと
|
132
|
-
課題に対してアプローチしたことを記載してください
|
133
|
-
|
134
|
-
###補足情報(言語/FW/ツール等のバージョンなど)
|
135
|
-
より詳細な情報
|