samedi 29 mai 2021

Add quiz to student in object oriented programming (Java)

Before you read, this is for my homework. The questions will be very specific.

I am writing some code that has an object class of the course and it allows the user to enter the quiz marks of the student. The quiz also has a scale for each mark. How this works is that there is an ArrayList that stores all the quiz marks of each student according to their studentId. The problem that I am having is that I can not include all the parameters that the method has. Since it was a boolean, what I have tried is to but the if-else function to the method. However, I cannot think of a way to incorporate the scale or have the if the statement has an error that the studentGrade cannot equal to "null". What I believe that should be in the block of code is that there would be something like studentGrade * scale for the adding for the total of the quiz marks but I am unsure how to implement that into my method.

This is my code:

import java.util.ArrayList;

public class Course{
    private ArrayList<Student> students;
    ArrayList<Student> quiz;

    public Course() {
        students = new ArrayList<Student>();
        quiz = new ArrayList<Student>();
    }

    Student addStudent (String name, String familyName){
        students.add(new Student(name,familyName));
        return null;
    }

    Student findStudent(long studentId) {
        for (Student e : students) {
            if (e.getStudentNumber() == studentId)
                return e;
        }
        return null;
    }

    Student deleteStudent(long studentId){
        students.remove(studentId);
        return null;
    }

    boolean addQuiz(long StudentId, double scale, double studentGrade){
        if (studentGrade == null || students.contains(StudentId)) {
            return false;
        }
        studentList.add(student);
        return true;
    }

    Student findTopStudent(){
        if (students.size() == 0)
            return null;
        Student largestYet = students.get(0);

        for(int i = 1; i < students.size(); i++){
            Student e = students.get(i);
            if(e.getQuizAverage() > largestYet.getQuizAverage())
                largestYet = e;
        }
        return largestYet;
    }

    double getAverage(){
//ignore this for now
    }

}

Aucun commentaire:

Enregistrer un commentaire