匹配正确答案和随机选择的学生成绩之间的过程

时间:2015-12-26 15:10:56

标签: java arrays

我正在研究测试问题

我有12名学生确定他们的姓名,身份证和姓氏。还有3个不同的组:0,1和2.每组有4名学生。

测试问题要求我使用数组并将学生的答案与密钥匹配(10个问题和5个可能的答案)

但是,我无法在正确答案与学生之间进行匹配。答案是因为两者都是if (aList instanceof LinkedList) { ((LinkedList)aList).peek(); } ,是吗?

以下是我的代码:

char

1 个答案:

答案 0 :(得分:0)

我已经阅读了您的评论,我认为您只需要在主要功能之外放置ID,名称,姓氏变量,并使它们静态。您也可以使用键阵列执行此操作。这样,其他方法可以使用这些变量。

import java.util.Random;
public class YEAH {
    private static final Random randomChar=new Random();

    private static String studentID[][] = new String [3][4];
    private static String studentName[][]= new String[3][4];
    private static String studentLastName[][]= new String [3][4];
    private static char key[]={'a','b','c','e','d','b','a','b','a','e'};

    public static void main(String[] args) {
        //your code here...
    }
    //...

修改
EDIT2

因此,此代码将计算每个人的点并显示它。希望它有所帮助。

import java.util.Random;
public class YEAH
{
    private static final Random randomChar=new Random();
    private static String studentID[][] = new String [3][4];
    private static String studentName[][]= new String[3][4];
    private static String studentLastName[][]= new String [3][4];
    private static char key[]={'a','b','c','e','d','b','a','b','a','e'};
    private static int studentPoints[][]=new int[3][4]
    private static int studentGrades[][]=new int[3][4];  //points*10
    private static char[][][] studentAnswers = new char[3][4][10];
        //store the answers given by students

    public static void main(String[] args)
    {
        studentName[0][0]="Cagatay";
        studentName[0][1]="Serhat";
            //... your code ...
        studentID[2][2]="D3";
        studentID[2][3]="D4";
        generateRandomAnswers();
        countPoints();
        PrintResults();
    }

    private static void PrintResults() {
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                System.out.Println(studentPoints[i][j] + "\t" +
                    studentID[i][j] + "\t" +
                    studentName[i][j] + "\t" +
                    studentLastName[i][j]);
            }
        }
    }

    private static void countPoints() {
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                for (int k = 0; k < 10; k++)
                {
                    studentPoints[i][j] = 0;
                    if (studentAswers[i][j][k] == key[i][j][k])
                    {
                        studentPoints[i][j]++;
                    }
                    studentGrades[i][j] = 10 * studentPoints[i][j];
                }
            }
        }
    }

    private static void generateRandomAnswers() {
        Random rnd = new Random();
        String alphabet="abcde";
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                for (int k = 0; k < 10; k++)
                {
                    studentAnswers[i][j][k]=alphabet.charAt(randomChar.nextInt(5));
                }
            }
        }
    }
}