gpt4 book ai didi

java - 如何在一页中显示不同类别的不同分数

转载 作者:行者123 更新时间:2023-12-01 18:08:51 27 4
gpt4 key购买 nike

我有 3 个不同的类别(每个类别都有不同的框架),它们通过“继续”按钮连接,最后一个框架是“完成”按钮。单击“完成”按钮后,我想显示每个类别的结果(按分),但每当我单击“完成”按钮时,最后一个类别的分数与两个类别的分数相同。请帮助我,我不知道该怎么做。

请注意,我的其他 2 个框架中没有代码来以结果形式显示分数

//这是我最后一帧中的代码...

try {
ResultSet rs = stmt.executeQuery(
"Select * from Questions where exam_category= 'Mathematics'");

while (rs.next()) {
Questions x = new Questions(
rs.getString("Question_Id"),
rs.getString("Subject_Code"),
rs.getString("Exam_Category"),
rs.getString("Question"),
rs.getString("Choice_A"),
rs.getString("Choice_B"),
rs.getString("Choice_C"),
rs.getString("Choice_D"),
rs.getString("Answer"));
list.add(x);
}

for (int i = 0; i < list.size(); i++) {
if(list.get(i).getAnswer().equals(userAnswer.get(i).toString())) {
score++;
System.out.print(score);
}
}

new Result(score, list).setVisible(true);
this.dispose();

} catch (SQLException ex) {
Logger.getLogger(LogicalReasoning.class.getName()).log(Level.SEVERE, null, ex);
}

//这是我的结果表单中的代码

public Result(int score, ArrayList<Questions> list) {
initComponents();
txtLogical.setText(String.valueOf(score + " out of " + list.size()));
txtEnglish.setText(String.valueOf(score + " out of " + list.size()));
txtMath.setText(String.valueOf(score + " out of " + list.size()));
}

最佳答案

尝试以下方法:

Result 应该得到 3 个主题的所有分数,所以我将其更改为:

public Result(int[] logicalResult, int[] englishResult, int[] mathResult) {
initComponents();
txtLogical.setText(logicalResult[0] + " out of " + logicalResult[1]);
txtEnglish.setText(englishResult[0] + " out of " + englishResult[1]);
txtMath.setText(mathResult[0] + " out of " + mathResult[1]);
}

每个主题结果都是一个 int[],其中包含 2 个值,即该主题的分数和问题数量。

然后为了满足这一点,我将有一个方法为给定主题返回那个小int[],因此采用您当前的实现,它将是这样的:

private int[] getScoreForTopic(String topic, List<Answer> userAnswers) {
int score = 0;
List<Questions> list = new ArrayList<>();

try {

Connection con;
// instantiate your connection

PreparedStatement stmt = con.prepareStatement(
"Select * from Questions where exam_category= ?");
stmt.setString(1, topic);
ResultSet rs = stmt.executeQuery();

while (rs.next()) {
Questions x = new Questions(
rs.getString("Question_Id"),
rs.getString("Subject_Code"),
rs.getString("Exam_Category"),
rs.getString("Question"),
rs.getString("Choice_A"),
rs.getString("Choice_B"),
rs.getString("Choice_C"),
rs.getString("Choice_D"),
rs.getString("Answer"));
list.add(x);
}

for (int i = 0; i < list.size(); i++) {
if(list.get(i).getAnswer().equals(userAnswer.get(i).toString())) {
score++;
System.out.print(score);
}
}


} catch (SQLException ex) {
// ...
}

return new int[] {score, list.size()};
}

最后,您可以这样创建 Result 对象:

int[] logicalResult = getScoreForTopic("Logical", userAnswerLogical);
int[] englishResult = getScoreForTopic("English", userAnswerEnglish);
int[] mathResult = getScoreForTopic("Mathematics", userAnswerMath);

new Result(logicalResult, englishResult, mathResult).setVisible(true);
this.dispose();

关于java - 如何在一页中显示不同类别的不同分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60504501/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com