#Trying to create a simple school system

70 messages · Page 1 of 1 (latest)

dusky socket
#

Hello guys. I'm trying to create a simple school system
It's a system that will receive only students and tests.
Students may have names and a kind of a list with test notes.
My system have to show the following options to the user:

  1. Register student
  2. List students
  3. See biggest note.

E. Exit

If I choose the 2st option, the output will be something like this :

  1. Carl
  2. Jean
  3. Peter

B. Back
E. Exit

If I choose 2 ( Jean ), I will have this :
Student : Jean
Tests Mean : 0
Biggest note : 0
Lower note : 0
Done tests : 0

  1. Register test for this student

B. Back
E. Exit

If I choose 1 In order to register test, I have to ask the user the test note and register it .

I have done some things already but I'm facing some troubles :
-> My student class:

import java.util.ArrayList;

public class Student {
    private String name; // 1o nome do aluno
    private ArrayList<Tests> tests; //ArrayList de provas

    public Student(String name){
        this.name=name;
        tests = new ArrayList<Tests>();
    }

    public String getName() {
        return name;
    }

    public int testsNumber(){
        return tests.size();
    }

    public int testsMean(ArrayList tests){
        int sum=0;
        for(int d : tests){
            sum+= d;
        }
    }
}

And I want to create a System class, where the user will can do the options that I showed in the beginning.

But idk how to store the grades in the Student class. I created a ArrayList of Tests but how can I register those tests ? I need help with :
-> Adding a grade into my tests ArrayList
-> Returning the mean of my tests ArrayList
-> Return biggest and lowest grades
(This 3 topics inside Student class. Or not. Idk)

And, in system class :
-> Create a new Student
-> Show the options that I send in the top
-> Make the options work

Can someone help me ? I think it's simple but idk how to proceed. I will send the Test class inside help chat.

stoic barnBOT
#

This post has been reserved for your question.

Hey @dusky socket! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

dusky socket
#

This is my Test class.

import java.util.Scanner;

public class Tests {
    private int grade;

    public Tests(int grade){
        this.grade=grade;
    }

}
dense reef
dusky socket
#

Yep

dusky socket
#
import java.util.ArrayList;

public class Student {
    private String name; // 1o nome do aluno
    private int biggestGrade;
    private int lowestGrade;
    private int mean;
    private int doneTests;

    public Student(String name){
        this.name=name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name){
    this.name= name}
}
#

I made some changes

#
import java.util.ArrayList;
import java.util.Scanner;

public class Tests {
    private ArrayList<Integer> grades ;

    public Tests(int grade){
        grades.add(grade);
    }
    public int testsMean(ArrayList tests){
        int sum = 0;

        for (int number : grades){
            sum += number;
        }

        int mean = sum/(grades.size());

        return mean;
    }


}
dense reef
#

let's talk about this method: ```java
public int testsMean(ArrayList tests){
int sum = 0;

    for (int number : grades){
        sum += number;
    }

    int mean = sum/(grades.size());

    return mean;
}```
#

you don't need to pass the tests arraylist, since class already contains the private ArrayList<Integer> grades ;

#

imo, it should be like public int testsMean()

dusky socket
#

got it

#

makes sense

dense reef
#

and, you need to add method that adds a grade to a test

#

because constructor allows to take only one integer

dusky socket
#

I'm not doing this in my constructor ?

#

Oh

#

Got it

#

So I have to call my constructor with no parameters and create a addGrade method, right ?

#

And then add grades

dense reef
#

That sounds more right to me. But still I have some questions, like

  • why multiple grades for one test?
  • if one test - one grade, shouldn't you create different tests and put the grade as a value?
    Because I don't really understand the structure you've chose to use
dusky socket
#

I agree with u, but idk how to implement this

#

In my head creating a Tests class in order to store my grades and then retrieving those grades in my Student class makes sense

#

But you're correct. It is one test-one grade relationship

dense reef
#

in that case you could implement it like:

  • student has list of Test, each test has grade and maybe a name of subject (for example, math)
  • when you need to find lowest - you run something like ```java
    int lowestGrade() {
    int lowest = 0;
    for (Test test : testList) {
    if (lowest > test.getGrade()) {
    lowest = test.getGrade();
    }
    }
    return lowest;
    }
dusky socket
#

Following that way, I have to make any change in my Tests class ?

#
import java.util.ArrayList;
import java.util.Scanner;

public class Tests {
    private ArrayList<Integer> grades ;

    public Tests(int grade){
        grades.add(grade);
    }
    public int testsMean(){
        int sum = 0;

        for (int number : grades){
            sum += number;
        }

        int mean = sum/(grades.size());

        return mean;
    }


}
#

That's it right now

#

Woops

#

Wrong code

dense reef
#

first if all, it should be called Test, not Tests, if you want to implement model "one test - one grade"

dusky socket
#

Better ?

dense reef
#

first of all, do we make one-to-one model, or one-to-many?

#

one test one grade, or one test many grades

dusky socket
#

One test grade

#

Then this method testsMean have to be inside students

dense reef
#

right

dusky socket
#

That's it ?

#

So I have to create a ArrayList of Test in my Student Class ?

dense reef
#

right

#

so Test could look like this:```java
class Test {
private int grade;

public Test(int grade) {
    this.grade = grade;
}

public int getGrade() {
    return grade;
}

}

#

maybe in the future you will want to add name of test

#

and relation to a subject

#

up to you

dusky socket
#

got it

#

how would be a method that add a Test ?

#

Considering the relationship one test-one grade

#

Because I can't use add method. The add wouldn't receive a grade, just another Test object

#

I have to instantiate a new Test object and then pass a grade as a parameter ?

dense reef
#

right

dusky socket
#
import java.util.ArrayList;

public class Student {
    private String name; // 1o nome do aluno
    private int biggestGrade;
    private int lowestGrade;
    private int mean;
    private int doneTests;

    private ArrayList<Test> tests = new ArrayList<Test>();

    public Student(String name){
        this.name=name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void addTest(int grade){
        Test newTest = new Test(grade);
        tests.add(newTest);
    }

    public int getLowestGrade(){
        int lowest = 0;
        for (Test test : tests) {
            if (lowest > test.getGrade()) {
                lowest = test.getGrade();
            }
        }
        return lowest;
    }

    public int getHighestGrade(){
        int highest = tests.indexOf(0);
        for (Test test : tests) {
            if (highest < test.getGrade()) {
                highest = test.getGrade();
            }
        }
        return highest;
    }
    public int testsMean(){
        int sum = 0;

        for (Test test : tests){
            sum += test.getGrade();
        }

        int mean = sum/(tests.size());

        return mean;
    }
}

#

Does this makes sense ?

dense reef
#

yeah, nice

#

maybe you should make testsMean as double, or round the mean

#

I mean that making it int, it will return 2 if mean was 2.9, since int just ignores the value after point

dusky socket
#

got it

#

i will try to implement the user options now in a System class

#

Scanner is the correct type to use, right ?

dense reef
#

yeah

#

I would do it static

#

well, it depends

#

anyways, make it as a field, not as a local object for each method

dense reef
dusky socket
#

nice !

#

I will finish it today