0

The title was hard to put out in enough detail for someone to click but essentially the problem is this. A user enters the amount of students they have

Pictured is how it works essentially: enter image description here

Ignore the outputs under each input, thats my testing, it then prints out the average for each student.

What I need is to get the average of each test, a test is the input line, aka 10,12 is test 1 and 11,13 is test 2 and I would print the averages

I have Objects for Test and Student and have finally managed to get the student items printing averages but not the Tests as i am not sure how to get the first of each line.

enter image description here

2
  • 3
    Please add the source code as actual code, so that we can use it to validate our answers. Commented Mar 24, 2016 at 1:54
  • Yeah sorry about that, I managed to get my answer just now so all good. Commented Mar 24, 2016 at 1:57

3 Answers 3

1

Sorry guys my question was unclear but I managed to get it. Here is my answer.

for(int i = 0; i != testCount;i++) {
        Test t = new Test(i);
        ArrayList temp = new ArrayList();
        for(Student stu: students) {
            temp.add(stu.getMarks().get(i).toString());
        }
        t.setTests(temp);
        tests.add(t);
    }
Sign up to request clarification or add additional context in comments.

Comments

0

The following is assuming all students take all tests

...
ArrayList tempM = new ArrayList();


for(int j = 0; j != s.length;j++ {
    Double mark = Double.parseDouble(s[j].toString())
    tempM.add(mark);
    Print(tempM.get(j).toString());
    stu.setMarks(tempM);

    Test test = null;
    if (tests.length < testCount) {
        test = new Test();
        tests.add(test);
    } else {
        test = tests.get(j);
    }
    // unknown ... test.addMark(mark)?  test.setMark(stu, mark)? ... something
}

Comments

0

You're possibly going to run in to problems where one student may have taken more tests than another. ie. what should happen if you enter 11 22 33 and then 10 20 30 40 for the second student?

The simple solution, assuming that all students take the same number of tests:

for (int i = 0; i<students.get(0).length; i++){    //Loop over the number of tests
    int total = 0; 
    for (Student student : students){              //Loop over students
         total += student.getMarks[0];             //Add the value for that test result for that student
    }
    Print("results for test " + i + ": " + total/students.size());  //print average
}

If some students do more tests than others - then you'll need to change your solution to accommodate.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.