根据用户输入的答案对学生进行测试分级 [英] grading a students test based on user input answers

查看:128
本文介绍了根据用户输入的答案对学生进行测试分级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




  • 声明/初始化一个数组,以保存12个问题的多项选择题的正确答案,其中
    答案是:B,D,A,A,C,A,B,A,C,D,B,A,
  • 使用for循环将单个学生的答案读入另一个数组
  • 评分测验并显示以下内容:

  • 学生名字

  • 测验分数以百分比形式显示的小数点后第一位(例如:12分中的7分将显示58.3%)


    然后是

    $ ul


  • 循环输入每个学生的答案,成绩测验,然后显示每个学生的成绩
  • 在所有学生处理完毕后,显示高分和低分的数值以及平均测验分数的百分比(1位十进制)


    程序应该看起来像:

     多少学生在课堂上? 2 
    为学生1输入姓名:Bob
    输入测验分数答案:<允许用户输入12个答案>
    Bob
    66.7%
    为学生2输入姓名:Fred
    输入测验分数答案:<允许用户输入12个答案>
    Fred
    91.7%
    高分为11分,低分为8
    平均分:79.2%

    我有这个数组,但我真的不知道如何使用for循环来实现。

      import java.util。*; 

    public class Lab4 {
    public static void main(String [] args){
    Scanner s = new Scanner(System.in);
    字符串名称;
    $ b $ char [] answerKey = {'B','D','A','A','C','A','B','A','C', 'D','B','A'};
    char [] userAnswers = new char [answerKey.length];


    $ b}
    }

    感谢迄今为止的帮助,
    我已经对它做了更多的工作,但是在输入答案后它给了我一个错误
    这就是我所拥有的

      import java.util。*; 
    import java.text。*;

    public class Lab4 {
    public static void main(String [] args){
    Scanner s = new Scanner(System.in);
    字符串输入;
    int学生;
    int correctAnswers = 0;
    $ b $ char [] answerKey = {'B','D','A','A','C','A','B','A','C', 'D','B','A'};
    char [] userAnswers = new char [answerKey.length];

    DecimalFormat df = new DecimalFormat(#0.0);

    System.out.print(你班上有多少学生?
    input = s.nextLine();
    students = Integer.parseInt(input);

    String [] name = new String [students];

    int j = 1;
    while(students> = j)
    {
    System.out.print(Enter name of student+ j +:);
    name [j] = s.nextLine();

    System.out.print(输入测验分数答案);
    userAnswers [answerKey.length] = s.next()。charAt(0);

    (int i = 0; i< userAnswers.length; ++ i)
    {
    if(userAnswers [i] == answerKey [i]);
    correctAnswers ++;


    System.out.print((df.format(correctAnswers / answerKey.length))+%);
    j ++;



    $ b $

    lockquote

    错误消息是线程mainjava.lang.ArrayIndexOutOfBoundsException中的异常:Lab4main中的
    (Lab4.java:29)

    我不确定它是什么意思或如何解决它。

    跳转到数组的快速教程 - > http:// www。 learn-java-tutorial.com/Arrays.cfm#.US09R-sjqy0



    如评论所述,我们不会为您编写代码,但我会尝试提供一些有用的指针:

    您将要提示用户有多少学生在课堂上,这应该已经教你的班。接受该输入并将其存储在一个变量中。

    在循环中创建一个来接受每个学生的数据。循环应该只运行多少次,就像用户指定的学生一样。



    在循环中接受你所有的学生数据,答案,姓名等。



    收集所有数据后,您需要将学生的答案与密钥进行比较。你可以在循环中使用或在循环中使用。我会推荐一个for循环,创建一些计数器以跟上正确或不正确的答案数,然后在循环之后执行数学运算以获得您的百分比。



    打印结果并重新启动循环。

    关于数组的Java文档: http://docs.oracle.com/javase/6/docs/api/ java / lang / reflect / Array.html



    一些快速数组特定指针:

    访问一个数组:

      String [] array = {a,b,c,d}; //创建数组
    System.out.println(array [0]); //打印出a
    System.out.println(array.length); //打印出数组元素的数目
    $ / code $ / pre

    希望这有帮助! p>

    I have to

    • Declare/Initialize an array to hold the correct answers to a 12 question multiple choice quiz whose answers are: 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', ‘B’, ‘A’
    • Read in the answers for a single student into another array using a for loop
    • ‘Grade’ the quiz and display the following:
      • Student Name
      • Quiz Score as a percentage to 1 decimal (ex: 7 out of 12 would display 58.3%)

    and then

    • First, at the top of your program, ask the user how many students there are in the class
    • Loop through and input each student’s answers, ‘grade’ quiz, and display the result for each student
    • After all students have been processed, display the values of the high and low scores and the average quiz score as a percentage (1 decimal)

    program should end up looking like:

    How many students are in the class? 2
    Enter name for Student 1: Bob
    Enter quiz score answers: <allow user to input 12 answers>
    Bob
    66.7%
    Enter name for Student 2: Fred
    Enter quiz score answers: <allow user to input 12 answers>
    Fred
    91.7%
    The high score is 11 and the low score is 8
    Average is: 79.2%
    

    I have this array set up but I really don't know how to implement it using the for loops.

    import java.util.*;
    
    public class Lab4 {
    public static void main(String[] args){
        Scanner s= new Scanner(System.in);
        String name;
    
        char [] answerKey= { 'B' , 'D' , 'A' , 'A' , 'C' , 'A' , 'B' , 'A' , 'C' , 'D' , 'B' , 'A' };
        char [] userAnswers = new char[answerKey.length];
    
    
    
    }
    }
    

    Thanks for the help so far guys, I've worked on it a bit more but its giving me an error after entering the answers this is what i have

    import java.util.*;
    import java.text.*;
    
    public class Lab4 {
        public static void main(String[] args){
        Scanner s= new Scanner(System.in);
        String input;
        int students;
        int correctAnswers=0;
    
        char [] answerKey= { 'B' , 'D' , 'A' , 'A' , 'C' , 'A' , 'B' , 'A' , 'C' , 'D' , 'B' , 'A' };
        char [] userAnswers = new char[answerKey.length];
    
            DecimalFormat df = new DecimalFormat("#0.0");
    
        System.out.print("how many students are in your class?");
        input = s.nextLine();
        students=Integer.parseInt(input);
    
        String [] name = new String[students];
    
        int j=1;
        while(students>=j)
        {
            System.out.print("Enter name of student" + j + ": ");
            name[j] = s.nextLine();
    
            System.out.print("Enter quiz score answers");
                userAnswers[answerKey.length] = s.next().charAt(0);
    
            for (int i = 0; i < userAnswers.length; ++i)
            {
                if(userAnswers[i]==answerKey[i]);
                correctAnswers++;
            }
    
            System.out.print((df.format(correctAnswers/answerKey.length)) + "%");
        j++;
    
        }
        }
    }
    

    The error message is Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 12 at Lab4.main(Lab4.java:29)

    I'm not sure what it means or how to fix it.

    解决方案

    Here's a jump to a quick tutorial on arrays -> http://www.learn-java-tutorial.com/Arrays.cfm#.US09R-sjqy0

    As stated in comments, we aren't going to write code for you, but I'll try to provide some helpful pointers:

    Your going to want to prompt the user for how many students are in the class, this should have been taught in your class. Accept that input and store it in a variable.

    Create a while loop to accept the data for each student. The loop should only run as many times as the user stated there were students.

    In the loop accept all your student data, answers, names, etc.

    After gathering all the data, you'll need to compare the students answer with the key. You can do this using a for loop or a while loop. I would recommend a for loop, create some kind of counter to keep up with how many answer were correct or incorrect, your choice then do the math after the loop to get your percentage.

    Print the results and restart the loop.

    Java Documentation on Arrays: http://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Array.html

    Some quick Array specific pointers:

    Access an array:

    String[] array = {"a", "b", "c", "d"}; //creates array
    System.out.println( array[0] ); //prints out "a"
    System.out.println( array.length ); //prints out "4", the number of elements in the array
    

    Hope this helps!

    这篇关于根据用户输入的答案对学生进行测试分级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆