mirror of
https://github.com/This-weiyuqing/javaAutoScore.git
synced 2026-10-17 18:55:31 +08:00
update
Added steps to write to score file.
This commit is contained in:
1 parent
1347614e57
commit
7c7166c6b7
4 files changed
+59
-24
No files matched your search
Binary file not shown.
Binary file not shown.
+25
-13
@@ -17,13 +17,14 @@ import java.io.IOException;
|
|||||||
import static autoScore.answer.readFireAnswer;
|
import static autoScore.answer.readFireAnswer;
|
||||||
import static autoScore.question.readFile;
|
import static autoScore.question.readFile;
|
||||||
import static autoScore.score.getScore;
|
import static autoScore.score.getScore;
|
||||||
|
import static autoScore.score.scoreToTxt;
|
||||||
|
|
||||||
public class mainGUI extends JFrame implements ActionListener {
|
public class mainGUI extends JFrame implements ActionListener {
|
||||||
// public static JTextField questionStudent;
|
// public static JTextField questionStudent;
|
||||||
JTextField questionStudent = new JTextField("问题的位置");
|
JTextField questionStudent = new JTextField("问题的位置");
|
||||||
//GridBagLayout questionText =new GridBagLayout();
|
//GridBagLayout questionText =new GridBagLayout();
|
||||||
// questionStudent.setLineWrap(true);
|
// questionStudent.setLineWrap(true);
|
||||||
int score;
|
//public int score;
|
||||||
Container c;//创建主容器
|
Container c;//创建主容器
|
||||||
private JTextArea question;
|
private JTextArea question;
|
||||||
private JButton A;
|
private JButton A;
|
||||||
@@ -96,14 +97,16 @@ public class mainGUI extends JFrame implements ActionListener {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
//int用来存储现在是第几题
|
//int用来存储现在是第几题
|
||||||
int whatQuestionW = 0;
|
int whatQuestionW = 0;
|
||||||
if (whatQuestionW < 20) {
|
int scoreUser =0 ;
|
||||||
|
if (whatQuestionW < 1) {
|
||||||
|
|
||||||
//int whatQuestionW =0;
|
//int whatQuestionW =0;
|
||||||
String str = new String();
|
String str = new String();
|
||||||
if (e.getActionCommand().equals("A")) {
|
if (e.getActionCommand().equals("A")) {
|
||||||
str = "A";
|
str = "A";
|
||||||
chooseDo(str, whatQuestionW);
|
/*scoreUser=*/chooseDo(str, whatQuestionW,scoreUser);
|
||||||
|
whatQuestionW++;
|
||||||
|
//actionPerformed(ActionEvent e);
|
||||||
}
|
}
|
||||||
/*str = "A";
|
/*str = "A";
|
||||||
char ch[] = str.toCharArray();
|
char ch[] = str.toCharArray();
|
||||||
@@ -124,44 +127,53 @@ public class mainGUI extends JFrame implements ActionListener {
|
|||||||
}*/
|
}*/
|
||||||
if (e.getActionCommand().equals("B")) {
|
if (e.getActionCommand().equals("B")) {
|
||||||
str = "B";
|
str = "B";
|
||||||
chooseDo(str, whatQuestionW);
|
/*scoreUser=*/chooseDo(str, whatQuestionW,scoreUser);whatQuestionW++;
|
||||||
// System.out.println(whatQuestionW);
|
// System.out.println(whatQuestionW);
|
||||||
}
|
}
|
||||||
if (e.getActionCommand().equals("C")) {
|
if (e.getActionCommand().equals("C")) {
|
||||||
str = "C";
|
str = "C";
|
||||||
chooseDo(str, whatQuestionW);
|
/*scoreUser=*/chooseDo(str, whatQuestionW,scoreUser);whatQuestionW++;
|
||||||
}
|
}
|
||||||
if (e.getActionCommand().equals("D")) {
|
if (e.getActionCommand().equals("D")) {
|
||||||
str = "D";
|
str = "D";
|
||||||
chooseDo(str, whatQuestionW);
|
/* scoreUser=*/chooseDo(str, whatQuestionW,scoreUser);whatQuestionW++;
|
||||||
}
|
}
|
||||||
whatQuestionW++;
|
whatQuestionW++;
|
||||||
} else {
|
} else {
|
||||||
//这里写最后结果被写入文件夹啊
|
//这里写最后结果被写入文件夹啊
|
||||||
|
try {
|
||||||
|
scoreToTxt(scoreUser);
|
||||||
|
} catch (IOException ioException) {
|
||||||
|
ioException.printStackTrace();
|
||||||
|
System.out.println("抛出异常1");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//按键之后要做的事
|
//按键之后要做的事
|
||||||
public void chooseDo(String str, int whatQuestionW) {
|
public int chooseDo(String str, int whatQuestionW,int score) {
|
||||||
//str = "A";
|
//str = "A";
|
||||||
char ch[] = str.toCharArray();
|
char ch[] = str.toCharArray();
|
||||||
char answer = ch[0];
|
char answer = ch[0];
|
||||||
|
//int score = 0;
|
||||||
try {
|
try {
|
||||||
getScore(score, answer, readFireAnswer(whatQuestionW));
|
score = getScore(score, answer, readFireAnswer(whatQuestionW));
|
||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
ioException.printStackTrace();
|
ioException.printStackTrace();
|
||||||
|
System.out.println("抛出异常2");
|
||||||
}
|
}
|
||||||
whatQuestionW++;
|
whatQuestionW++;
|
||||||
System.out.println(whatQuestionW);
|
//System.out.println(whatQuestionW);
|
||||||
|
System.out.println(score);
|
||||||
try {
|
try {
|
||||||
questionStudent.setText(readFile(1));
|
questionStudent.setText(readFile(1));
|
||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
ioException.printStackTrace();
|
ioException.printStackTrace();System.out.println("抛出异常3");
|
||||||
}
|
}return score;
|
||||||
//mainGUI=new mainGUI();
|
//mainGUI=new mainGUI();
|
||||||
//actionPerformed(ActionEvent e);
|
//actionPerformed(ActionEvent e);
|
||||||
|
//chooseDo(str,whatQuestionW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*public clstatic void main(String[] args) throws IOException {
|
/*public clstatic void main(String[] args) throws IOException {
|
||||||
|
|||||||
+34
-11
@@ -1,15 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 魏遇卿 All Rights Reserved.
|
||||||
|
* FileName: a.java
|
||||||
|
* @author: 魏遇卿@date: 2020/6/19 下午8:02@version: 1.0
|
||||||
|
* E-mail:358614401@qq.com
|
||||||
|
* Code with UTF-8
|
||||||
|
*/
|
||||||
package autoScore;
|
package autoScore;
|
||||||
|
|
||||||
public class score {
|
import java.io.BufferedWriter;
|
||||||
public static int getScore (int score,char choose,char anwser){
|
import java.io.File;
|
||||||
if (choose ==anwser ) {
|
import java.io.FileWriter;
|
||||||
score++;
|
import java.io.IOException;
|
||||||
return score;
|
|
||||||
}else {
|
|
||||||
return score;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static void scoreToTxt(/*String name*,*/int score){
|
|
||||||
|
|
||||||
|
public class score {
|
||||||
|
public static int getScore(int score, char choose, char anwser) {
|
||||||
|
if (choose == anwser) {
|
||||||
|
score++;
|
||||||
|
return score;
|
||||||
|
} else {
|
||||||
|
return score;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void scoreToTxt(/*String name*,*/int score) throws IOException {
|
||||||
|
File writename = new File("D:\\WindowsCToD\\fire\\GeneticsMultipleChoice\\Score\\output.txt"); // 相对路径,如果没有则要建立一个新的output。txt文件
|
||||||
|
writename.createNewFile();
|
||||||
|
BufferedWriter out = new BufferedWriter(new FileWriter(writename));
|
||||||
|
out.write(/*name+*/"score:" + score + "\r\n"); // \r\n即为换行
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public static void main(String[] args) throws IOException {
|
||||||
|
scoreToTxt(5);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user