Vestibular system using JAVA

3

I have a college job to do, which is to create a college entrance 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 student data,   check which students are approved for each course and,   later, write to a file named   "certificados_cursotal.txt" (one for each course), sorted by the   student. If two or more students have the same grade, they must   be ordered by their name and, in case of equal names, order by   enrollment.

I have already created all the classes mentioned in the link. The file class is already saving all the required data in the vestibular.txt file. I just do not know how to do the other two files by filtering the approved ones for each course according to the grades.

- Class's I've already done. Google Drive link

    
asked by anonymous 11.11.2014 / 00:05

1 answer

4

Well, I've developed a solution that caters more or less to what you want. The solution read a vestibular.txt file with comma-separated attributes, then a Student object is created for each row (each student in the case) and then saved in an ArrayList to be processed and then generated the new document, follow the code .

First we have the class Aluno.java, this class we will use to be able to manipulate our student, in case the list is sorted by the note.

Student.java

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, I overwritten the compareTo method, so when to use Collections.sort () to be able to sort by note.

The student class being ready, now follows the class ProcessorNotes. 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 adds it to the list. After all the students added in the list it is possible to do Collections.sort, which will order students by note.

Then after the ordered list I did just a Foreach saving only those students who have grade above 8.

ProcessorNotes.java

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.

    
11.11.2014 / 01:19