Малко помощ.
Ако може някой да ми помогне искам да прочета файла на края,и да сортирам по среден успех на всеки студент,примерно петима студента.И да излезе на конзолата сортирано по успеха.
package student;
import java.io.*;
import static java.lang.System.in;
import java.util.Scanner;
import java.util.Scanner;
class Student{
private String name;
private int course;
private String specialty;
private int facultyNumber;
private double averageSuccess;
public Student(String name,int course,String specialty,int facultyNumber,double averageSuccess){
this.name = name;
this.course = course;
this.specialty = specialty;
this.facultyNumber = facultyNumber;
this.averageSuccess = averageSuccess;
}
public String getName(){
return name;
}
public int getCourese(){
return course;
}
public String getSpecialty(){
return specialty;
}
public int getFacultyNumber(){
return facultyNumber;
}
public double getAverageSuccess(){
return averageSuccess;
}
}
public class Students {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(System.in);
PrintStream fileWriter = new PrintStream("student.txt");
File file = new File("student.txt");
for (int i = 0; i < 2; i++) {
System.out.println("Enter the Name of Students");
String name = input.next();
System.out.println("Enter the course of Students");
int course = input.nextInt();
System.out.println("Enter the Specialty of Students");
String specialty = input.next();
System.out.println("Enter the Faculty number of Students");
int facultyNumber = input.nextInt();
System.out.println("Enter the averageSuccess of Students");
double averageSuccess = input.nextDouble();
fileWriter.println(name+" "+course+" "+specialty+" "+facultyNumber+" "+averageSuccess);
}
fileWriter.close();
Scanner fileReader = new Scanner(file);
String[] array = new String [2];
for (int i = 0; i < 2; i++) {
array[i]=fileReader.nextLine();
System.out.println( "Student "+array[i]);
}
fileReader.close();
}
}