Vestibular system using JAVA

Asked

Viewed 476 times

3

I have a college assignment to do, which is to create a vestibular system. The work is on the link, click here, and I am in doubt on the following topic:

The program should read from the file "vestibular.txt" the students' data, verify which students are approved for each course and, later, write to a file named "aprovados_cursotal.txt" (one for each course), ordered by the note of student. If two or more students have the same grade, they must be ordered by their name and, in the case of equal names, by registration.

I already created all the classes mentioned in the link. The file class, already saving all the necessary data in the vestibular.txt file. Only I don’t know how to make the other two files filtering the approved of each course according to the grades.

-- Class’s I’ve ever done. Google Drive https://drive.google.com/a/sga.pucminas.br/folderview?id=0ByaGP-vb3NW7cVBYUzN0VjFEWGM&usp=sharing

  • 1

    So put what you did.

  • 1

    @Raulgoulart The problem you mentioned is actually quite broad and can be divided into smaller problems. I think you better start with one of them, who you’re having trouble with, and explain how you tried to attack him and what difficulties you encountered. Besides putting on what you did, like the mustache said.

  • 1

    Divide to conquer! Ask a quick and objective question that we can answer you. See the guide [Ask]

  • Raul, seeing your question earlier I asked two classes that solve the problem, I will post and you check, not so agree with what the link asks. But you can look at my code and then tell me what you’re not getting, or specify what you’re not getting.

  • @bigown, posted the content I’ve made.

1 answer

4


Well, I’ve developed a solution that fits more or less what you want. The solution reads a vestibular.txt file with the attributes separated by comma, then a Student object is created for each line (each student in the case) and then is saved in an Arraylist to be processed and then generated the new document, follows the code.

First we have the class Student.java, this class we will use to manipulate our student, in case order the list by grade.

Java student.

public class Aluno implements Comparable<Aluno> {

    private String nome;
    private String curso;
    private int inscricao;
    private double nota;

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }


    //Outros getters e setters

    @Override
    public int compareTo(Aluno a) {
        if(this.nota > a.nota) return 1;
        if(this.nota > a.nota) return -1;
        return 0;
    }   
}

In the student class I implemented the Comparable interface, overriding the compareTo method, so when to use Collections.Sort() I can sort by note.

The student class being ready, now follows the class Processed. The class is well commented. But what it basically does: Read the vestibular.txt file and separates the attributes that are between the commas. After that a student is created to save the attributes in it and then add it to the list. After all students added to the list it is possible to do Collections.Sort, which will sort students by grade.

Then after the orderly list I made only one Foreach saving only students who have grade above 8.

Java processors.

public class ProcessadorNotas {

    public static void main(String[] args) throws IOException {

        Aluno aluno = null;
        ArrayList<Aluno> listaDeAlunos = new ArrayList<Aluno>();

        Scanner sc = new Scanner(new FileInputStream("vestibular.txt"));

        while(sc.hasNextLine()) {
            String linha = sc.nextLine();
            //Separamos os dados por virgula, e cada campo será armazenado em uma posição da array.
            String dados[] = linha.split(",");
            //Criamos um objeto aluno e setamos os seus atributos para depois colarmos na lista.
            aluno = new Aluno();
            aluno.setNome(dados[0]);
            aluno.setInscricao(Integer.parseInt(dados[1]));
            aluno.setNota(Double.parseDouble(dados[2]));
            aluno.setCurso(dados[3]);
            //Adicionamos o aluno a lista.
            listaDeAlunos.add(aluno);
        }       

        //Vamos ordernar os alunos por notas, então iremos apenas ver quais estão acima da média na hora de escrever.

        Collections.sort(listaDeAlunos);

        //Agora já temos a lista de alunos, agora vamos escrever um outro arquivo com o resultado_vestibular
        //Vamos supor que para ser aprovado, o aluno tem que ter nota 8. 

        PrintStream ps = new PrintStream("aprovados_vestibular.txt");

        for(Aluno a : listaDeAlunos) {
            if(a.getNota() > 8) {
                ps.print(a.getNome()+",");
                ps.print(String.valueOf(a.getInscricao())+",");
                ps.print(String.valueOf(a.getNota())+",");
                ps.print(a.getCurso());
                ps.println();
            }
        }       
        ps.close();
    }   
}

If you have any questions put there in the comments, thanks.

  • I could not order the list no.

  • In the student class you inplementou the comparable?

  • I haven’t learned that yet u.u

  • Ih man, so if you haven’t learned yet, probably the teacher won’t accept it that way =/

  • 2

    @Raulgoulart tries to do it himself, or you’ll never learn to program again...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.