回答編集履歴
4
コメント間違い
answer
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
質問文は固定で、選択のYESの個数で判定するようなものですよね?
|
|
2
|
-
質問に重み付けがあったりするともっと本格的ですが、回答は単純に個数で判定しました。
|
|
3
|
-
文字で入力するのは面倒なのでボタンにしました。
|
|
4
|
-
|
|
5
|
-
```Java
|
|
6
|
-
import java.io.IOException;
|
|
7
|
-
import java.nio.charset.StandardCharsets;
|
|
8
|
-
import java.nio.file.Files;
|
|
9
|
-
import java.nio.file.Paths;
|
|
10
|
-
import java.util.Arrays;
|
|
11
|
-
import java.util.List;
|
|
12
|
-
|
|
13
|
-
import javafx.application.Application;
|
|
14
|
-
import javafx.event.ActionEvent;
|
|
15
|
-
import javafx.event.EventHandler;
|
|
16
|
-
import javafx.geometry.Insets;
|
|
17
|
-
import javafx.geometry.Pos;
|
|
18
|
-
import javafx.scene.Scene;
|
|
19
|
-
import javafx.scene.control.Button;
|
|
20
|
-
import javafx.scene.control.Label;
|
|
21
|
-
import javafx.scene.layout.BorderPane;
|
|
22
|
-
import javafx.scene.layout.VBox;
|
|
23
|
-
import javafx.stage.Stage;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
public class Main extends Application {
|
|
27
|
-
public static void main(String[] args) { launch(args); }
|
|
28
|
-
|
|
29
|
-
@Override public void start(Stage primaryStage) {
|
|
30
|
-
BorderPane root = new BorderPane();
|
|
31
|
-
Button button = new Button("心理テストだよ");
|
|
32
|
-
button.setOnAction(new seEventHandler());
|
|
33
|
-
|
|
34
|
-
root.setCenter(button);
|
|
35
|
-
primaryStage.setScene(new Scene(root, 500, 400));
|
|
36
|
-
primaryStage.show();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
class seEventHandler implements EventHandler<ActionEvent> {
|
|
41
|
-
private Label label;
|
|
42
|
-
private Button button1;
|
|
43
|
-
private Button button2;
|
|
44
|
-
|
|
45
|
-
private String[][] questions; // 質問の配列の配列(質問個数分の配列の中に「質問文・選択肢1・選択肢2」の配列が入っている)
|
|
46
|
-
private int index; // 今の質問インデックス
|
|
47
|
-
private int dog;
|
|
48
|
-
|
|
49
|
-
@Override public void handle(ActionEvent event) {
|
|
50
|
-
Stage stage = new Stage();
|
|
51
|
-
BorderPane root = new BorderPane();
|
|
52
|
-
root.setPadding(new Insets(10, 10, 10, 10));
|
|
53
|
-
stage.setScene(new Scene(root, 400, 300));
|
|
54
|
-
|
|
55
|
-
label = new Label();
|
|
56
|
-
root.setCenter(label);
|
|
57
|
-
|
|
58
|
-
button1 = new Button();
|
|
59
|
-
button2 = new Button();
|
|
60
|
-
button1.setOnAction(ae -> { dog++; next(); });
|
|
61
|
-
button2.setOnAction(ae -> next());
|
|
62
|
-
|
|
63
|
-
VBox box = new VBox(10, button1, button2);
|
|
64
|
-
box.setAlignment(Pos.CENTER);
|
|
65
|
-
root.setBottom(box);
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
createCSV();
|
|
69
|
-
loadCSV();
|
|
70
|
-
} catch (IOException e) {
|
|
71
|
-
e.printStackTrace();
|
|
72
|
-
}
|
|
73
|
-
next();
|
|
74
|
-
|
|
75
|
-
stage.show();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private void next() {
|
|
79
|
-
if (index < questions.length) { // 質問作成
|
|
80
|
-
label.setText(questions[index][0]); // questions[index][0]が質問文
|
|
81
|
-
button1.setText(questions[index][1]); // questions[index][
|
|
82
|
-
button2.setText(questions[index][2]);
|
|
83
|
-
|
|
84
|
-
index++;
|
|
85
|
-
} else { // 結果判定
|
|
86
|
-
String result;
|
|
87
|
-
switch (dog) {
|
|
88
|
-
case 0: result = "あなたは完全に猫派です!"; break;
|
|
89
|
-
case 1: result = "あなたはどちらかというと猫派です。"; break;
|
|
90
|
-
case 2: result = "あなたはどちらかというと犬派です。"; break;
|
|
91
|
-
default: result = "あなたは完全に犬派です!"; break;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
label.setText(result);
|
|
95
|
-
button1.setVisible(false);
|
|
96
|
-
button2.setVisible(false);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
private void loadCSV() throws IOException {
|
|
101
|
-
List<String> lines = Files.readAllLines(Paths.get("test.csv"), StandardCharsets.UTF_8); // ファイルを1行毎のリストに読み込み
|
|
102
|
-
|
|
103
|
-
questions = new String[lines.size()][]; // 行数分配列を確保
|
|
104
|
-
for (int i = 0; i < lines.size(); i++) {
|
|
105
|
-
String[] split = lines.get(i).split(","); // カンマで区切って「質問文・選択肢1・選択肢2」の配列を作成
|
|
106
|
-
questions[i] = split; // questions配列のi番目の中にまた配列を入れた
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// というtest.csvがあるテイで
|
|
111
|
-
private void createCSV() throws IOException {
|
|
112
|
-
List<String> lines = Arrays.asList(
|
|
113
|
-
"休日の過ごし方は?,みんなでワイワイ,ひとりで趣味を",
|
|
114
|
-
"久しぶりに雪が降ったらどうする?,外で駆け回る,コタツでぬくぬく",
|
|
115
|
-
"褒められるとついついしてしまうことは?,よだれを垂らしてしまう,興味ないふりをしてしまう");
|
|
116
|
-
|
|
117
|
-
Files.write(Paths.get("test.csv"), lines, StandardCharsets.UTF_8);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
軽く説明を入れましたが、不明点があればコメントしてください。
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
---
|
|
126
|
-
|
|
127
|
-
一刻も早くプログラムを完成させたい気持ちはわかりますが、
|
|
128
|
-
[Eclipse - ファイルの読み込みのエラーが原因なのでしょうか…?|teratail](https://teratail.com/questions/314041)
|
|
129
|
-
|
|
130
|
-
を見る限り到底動くと思えません。ファイルを読み込む以前の問題です。
|
|
131
|
-
|
|
1
|
+
質問文は固定で、選択のYESの個数で判定するようなものですよね?
|
|
2
|
+
質問に重み付けがあったりするともっと本格的ですが、回答は単純に個数で判定しました。
|
|
3
|
+
文字で入力するのは面倒なのでボタンにしました。
|
|
4
|
+
|
|
5
|
+
```Java
|
|
6
|
+
import java.io.IOException;
|
|
7
|
+
import java.nio.charset.StandardCharsets;
|
|
8
|
+
import java.nio.file.Files;
|
|
9
|
+
import java.nio.file.Paths;
|
|
10
|
+
import java.util.Arrays;
|
|
11
|
+
import java.util.List;
|
|
12
|
+
|
|
13
|
+
import javafx.application.Application;
|
|
14
|
+
import javafx.event.ActionEvent;
|
|
15
|
+
import javafx.event.EventHandler;
|
|
16
|
+
import javafx.geometry.Insets;
|
|
17
|
+
import javafx.geometry.Pos;
|
|
18
|
+
import javafx.scene.Scene;
|
|
19
|
+
import javafx.scene.control.Button;
|
|
20
|
+
import javafx.scene.control.Label;
|
|
21
|
+
import javafx.scene.layout.BorderPane;
|
|
22
|
+
import javafx.scene.layout.VBox;
|
|
23
|
+
import javafx.stage.Stage;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
public class Main extends Application {
|
|
27
|
+
public static void main(String[] args) { launch(args); }
|
|
28
|
+
|
|
29
|
+
@Override public void start(Stage primaryStage) {
|
|
30
|
+
BorderPane root = new BorderPane();
|
|
31
|
+
Button button = new Button("心理テストだよ");
|
|
32
|
+
button.setOnAction(new seEventHandler());
|
|
33
|
+
|
|
34
|
+
root.setCenter(button);
|
|
35
|
+
primaryStage.setScene(new Scene(root, 500, 400));
|
|
36
|
+
primaryStage.show();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class seEventHandler implements EventHandler<ActionEvent> {
|
|
41
|
+
private Label label;
|
|
42
|
+
private Button button1;
|
|
43
|
+
private Button button2;
|
|
44
|
+
|
|
45
|
+
private String[][] questions; // 質問の配列の配列(質問個数分の配列の中に「質問文・選択肢1・選択肢2」の配列が入っている)
|
|
46
|
+
private int index; // 今の質問インデックス
|
|
47
|
+
private int dog;
|
|
48
|
+
|
|
49
|
+
@Override public void handle(ActionEvent event) {
|
|
50
|
+
Stage stage = new Stage();
|
|
51
|
+
BorderPane root = new BorderPane();
|
|
52
|
+
root.setPadding(new Insets(10, 10, 10, 10));
|
|
53
|
+
stage.setScene(new Scene(root, 400, 300));
|
|
54
|
+
|
|
55
|
+
label = new Label();
|
|
56
|
+
root.setCenter(label);
|
|
57
|
+
|
|
58
|
+
button1 = new Button();
|
|
59
|
+
button2 = new Button();
|
|
60
|
+
button1.setOnAction(ae -> { dog++; next(); });
|
|
61
|
+
button2.setOnAction(ae -> next());
|
|
62
|
+
|
|
63
|
+
VBox box = new VBox(10, button1, button2);
|
|
64
|
+
box.setAlignment(Pos.CENTER);
|
|
65
|
+
root.setBottom(box);
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
createCSV();
|
|
69
|
+
loadCSV();
|
|
70
|
+
} catch (IOException e) {
|
|
71
|
+
e.printStackTrace();
|
|
72
|
+
}
|
|
73
|
+
next();
|
|
74
|
+
|
|
75
|
+
stage.show();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private void next() {
|
|
79
|
+
if (index < questions.length) { // 質問作成
|
|
80
|
+
label.setText(questions[index][0]); // questions[index][0]が質問文
|
|
81
|
+
button1.setText(questions[index][1]); // questions[index][1]は選択肢1
|
|
82
|
+
button2.setText(questions[index][2]); // questions[index][2]は選択肢2
|
|
83
|
+
|
|
84
|
+
index++;
|
|
85
|
+
} else { // 結果判定
|
|
86
|
+
String result;
|
|
87
|
+
switch (dog) {
|
|
88
|
+
case 0: result = "あなたは完全に猫派です!"; break;
|
|
89
|
+
case 1: result = "あなたはどちらかというと猫派です。"; break;
|
|
90
|
+
case 2: result = "あなたはどちらかというと犬派です。"; break;
|
|
91
|
+
default: result = "あなたは完全に犬派です!"; break;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
label.setText(result);
|
|
95
|
+
button1.setVisible(false);
|
|
96
|
+
button2.setVisible(false);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private void loadCSV() throws IOException {
|
|
101
|
+
List<String> lines = Files.readAllLines(Paths.get("test.csv"), StandardCharsets.UTF_8); // ファイルを1行毎のリストに読み込み
|
|
102
|
+
|
|
103
|
+
questions = new String[lines.size()][]; // 行数分配列を確保
|
|
104
|
+
for (int i = 0; i < lines.size(); i++) {
|
|
105
|
+
String[] split = lines.get(i).split(","); // カンマで区切って「質問文・選択肢1・選択肢2」の配列を作成
|
|
106
|
+
questions[i] = split; // questions配列のi番目の中にまた配列を入れた
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// というtest.csvがあるテイで
|
|
111
|
+
private void createCSV() throws IOException {
|
|
112
|
+
List<String> lines = Arrays.asList(
|
|
113
|
+
"休日の過ごし方は?,みんなでワイワイ,ひとりで趣味を",
|
|
114
|
+
"久しぶりに雪が降ったらどうする?,外で駆け回る,コタツでぬくぬく",
|
|
115
|
+
"褒められるとついついしてしまうことは?,よだれを垂らしてしまう,興味ないふりをしてしまう");
|
|
116
|
+
|
|
117
|
+
Files.write(Paths.get("test.csv"), lines, StandardCharsets.UTF_8);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
軽く説明を入れましたが、不明点があればコメントしてください。
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
一刻も早くプログラムを完成させたい気持ちはわかりますが、
|
|
128
|
+
[Eclipse - ファイルの読み込みのエラーが原因なのでしょうか…?|teratail](https://teratail.com/questions/314041)
|
|
129
|
+
|
|
130
|
+
を見る限り到底動くと思えません。ファイルを読み込む以前の問題です。
|
|
131
|
+
|
|
132
132
|
回答プログラムは`test.csv`を作成してから読み込むようになっているので、どこにできているか確認してみてください。
|
3
メニュー画面付
answer
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
質問に重み付けがあったりするともっと本格的ですが、回答は単純に個数で判定しました。
|
|
3
3
|
文字で入力するのは面倒なのでボタンにしました。
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
```Java
|
|
7
6
|
import java.io.IOException;
|
|
8
7
|
import java.nio.charset.StandardCharsets;
|
|
@@ -12,6 +11,8 @@
|
|
|
12
11
|
import java.util.List;
|
|
13
12
|
|
|
14
13
|
import javafx.application.Application;
|
|
14
|
+
import javafx.event.ActionEvent;
|
|
15
|
+
import javafx.event.EventHandler;
|
|
15
16
|
import javafx.geometry.Insets;
|
|
16
17
|
import javafx.geometry.Pos;
|
|
17
18
|
import javafx.scene.Scene;
|
|
@@ -25,6 +26,18 @@
|
|
|
25
26
|
public class Main extends Application {
|
|
26
27
|
public static void main(String[] args) { launch(args); }
|
|
27
28
|
|
|
29
|
+
@Override public void start(Stage primaryStage) {
|
|
30
|
+
BorderPane root = new BorderPane();
|
|
31
|
+
Button button = new Button("心理テストだよ");
|
|
32
|
+
button.setOnAction(new seEventHandler());
|
|
33
|
+
|
|
34
|
+
root.setCenter(button);
|
|
35
|
+
primaryStage.setScene(new Scene(root, 500, 400));
|
|
36
|
+
primaryStage.show();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class seEventHandler implements EventHandler<ActionEvent> {
|
|
28
41
|
private Label label;
|
|
29
42
|
private Button button1;
|
|
30
43
|
private Button button2;
|
|
@@ -33,11 +46,11 @@
|
|
|
33
46
|
private int index; // 今の質問インデックス
|
|
34
47
|
private int dog;
|
|
35
48
|
|
|
36
|
-
@Override
|
|
37
|
-
public void
|
|
49
|
+
@Override public void handle(ActionEvent event) {
|
|
50
|
+
Stage stage = new Stage();
|
|
38
51
|
BorderPane root = new BorderPane();
|
|
39
52
|
root.setPadding(new Insets(10, 10, 10, 10));
|
|
40
|
-
|
|
53
|
+
stage.setScene(new Scene(root, 400, 300));
|
|
41
54
|
|
|
42
55
|
label = new Label();
|
|
43
56
|
root.setCenter(label);
|
|
@@ -51,11 +64,15 @@
|
|
|
51
64
|
box.setAlignment(Pos.CENTER);
|
|
52
65
|
root.setBottom(box);
|
|
53
66
|
|
|
67
|
+
try {
|
|
54
|
-
|
|
68
|
+
createCSV();
|
|
55
|
-
|
|
69
|
+
loadCSV();
|
|
70
|
+
} catch (IOException e) {
|
|
71
|
+
e.printStackTrace();
|
|
72
|
+
}
|
|
56
73
|
next();
|
|
57
74
|
|
|
58
|
-
|
|
75
|
+
stage.show();
|
|
59
76
|
}
|
|
60
77
|
|
|
61
78
|
private void next() {
|
2
修正
answer
CHANGED
|
@@ -107,9 +107,6 @@
|
|
|
107
107
|
|
|
108
108
|
---
|
|
109
109
|
|
|
110
|
-
こちらもvarを修正しました。
|
|
111
|
-
Java8ならこれで動くと思うので、求めているものとどこが違うのか**コメントしてください**。
|
|
112
|
-
|
|
113
110
|
一刻も早くプログラムを完成させたい気持ちはわかりますが、
|
|
114
111
|
[Eclipse - ファイルの読み込みのエラーが原因なのでしょうか…?|teratail](https://teratail.com/questions/314041)
|
|
115
112
|
|
1
var
answer
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
|
|
36
36
|
@Override
|
|
37
37
|
public void start(Stage primaryStage) throws IOException {
|
|
38
|
-
|
|
38
|
+
BorderPane root = new BorderPane();
|
|
39
39
|
root.setPadding(new Insets(10, 10, 10, 10));
|
|
40
40
|
primaryStage.setScene(new Scene(root, 400, 300));
|
|
41
41
|
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
button1.setOnAction(ae -> { dog++; next(); });
|
|
48
48
|
button2.setOnAction(ae -> next());
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
VBox box = new VBox(10, button1, button2);
|
|
51
51
|
box.setAlignment(Pos.CENTER);
|
|
52
52
|
root.setBottom(box);
|
|
53
53
|
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
List<String> lines = Files.readAllLines(Paths.get("test.csv"), StandardCharsets.UTF_8); // ファイルを1行毎のリストに読み込み
|
|
85
85
|
|
|
86
86
|
questions = new String[lines.size()][]; // 行数分配列を確保
|
|
87
|
-
for (
|
|
87
|
+
for (int i = 0; i < lines.size(); i++) {
|
|
88
88
|
String[] split = lines.get(i).split(","); // カンマで区切って「質問文・選択肢1・選択肢2」の配列を作成
|
|
89
89
|
questions[i] = split; // questions配列のi番目の中にまた配列を入れた
|
|
90
90
|
}
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
|
|
93
93
|
// というtest.csvがあるテイで
|
|
94
94
|
private void createCSV() throws IOException {
|
|
95
|
-
|
|
95
|
+
List<String> lines = Arrays.asList(
|
|
96
96
|
"休日の過ごし方は?,みんなでワイワイ,ひとりで趣味を",
|
|
97
97
|
"久しぶりに雪が降ったらどうする?,外で駆け回る,コタツでぬくぬく",
|
|
98
98
|
"褒められるとついついしてしまうことは?,よだれを垂らしてしまう,興味ないふりをしてしまう");
|
|
@@ -101,4 +101,18 @@
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
```
|
|
104
|
+
|
|
104
|
-
軽く説明を入れましたが、不明点があればコメントしてください。
|
|
105
|
+
軽く説明を入れましたが、不明点があればコメントしてください。
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
こちらもvarを修正しました。
|
|
111
|
+
Java8ならこれで動くと思うので、求めているものとどこが違うのか**コメントしてください**。
|
|
112
|
+
|
|
113
|
+
一刻も早くプログラムを完成させたい気持ちはわかりますが、
|
|
114
|
+
[Eclipse - ファイルの読み込みのエラーが原因なのでしょうか…?|teratail](https://teratail.com/questions/314041)
|
|
115
|
+
|
|
116
|
+
を見る限り到底動くと思えません。ファイルを読み込む以前の問題です。
|
|
117
|
+
|
|
118
|
+
回答プログラムは`test.csv`を作成してから読み込むようになっているので、どこにできているか確認してみてください。
|