
Respuesta :
Answer:
See explaination
Explanation:
Student.java
public class Student implements Comparable<Student> {
private String firstName;
private String lastName;
private float gpa;
public Student(String fn, String ln, float gpa) {
firstName = fn;
lastName = ln;
this.gpa = gpa;
}
public String getFirst() {
return firstName;
}
public String getLast() {
return lastName;
}
public float getGpa() {
return gpa;
}
public int compareTo(Student other) {
return (lastName.compareTo(other.lastName));
}
}
Answer:
Check the explanation
Explanation:
Student.java
public class Student implements Comparable<Student> {
 private String firstName;
 private String lastName;
 private float gpa;
Â
Â
 public Student(String fn, String ln, float gpa) {
   firstName = fn;
   lastName = ln;
   this.gpa = gpa;
 }
 public String getFirst() {
   return firstName;
 }
 public String getLast() {
   return lastName;
 }
 public float getGpa() {
   return gpa;
 }
 public int compareTo(Student other) {
   return (lastName.compareTo(other.lastName));
 }
Â
}
StudnetProcessor.java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class StudentProcessor {
 public static void main(String[] args) throws NumberFormatException, IOException {
   Scanner sc = new Scanner(System.in);
   System.out.print("Enter input filename: ");
   String inFile = sc.nextLine();
  Â
   ArrayList<Student> students = readFile(inFile);
  Â
   System.out.print("Enter output filename: ");
   String outFile = sc.nextLine();
  Â
   writeFile(students, outFile);
   sc.close();
 }
Â
 private static ArrayList<Student> readFile(String inFile) throws NumberFormatException, IOException {
   ArrayList<Student> students = new ArrayList<>();
   BufferedReader br = new BufferedReader(new FileReader(inFile));
  Â
   String st;
   while ((st = br.readLine()) != null) {
     String[] parts = st.split(" ");
     Student student = new Student(parts[1], parts[0], Float.parseFloat(parts[2]));
     students.add(student);
   }
   br.close();
   return students;
 }
 private static void writeFile(ArrayList<Student> list, String outFile) throws IOException {
   ArrayList<Student> students = new ArrayList<>();
   for(Student student: list) {
     if (student.getGpa() >= 3) {
       students.add(student);
     }
   }
   Collections.sort(students);
  Â
   FileWriter myWriter = new FileWriter(outFile);
   for(Student student: students) {
     String str = String.format("%-10s %-10s %5.2f", student.getLast(), student.getFirst(), student.getGpa());
     myWriter.write(str);
   }
   myWriter.close();
 }
}