fork download
  1. public class Student {
  2. private String name;
  3. private double[] grades;
  4.  
  5. public String getName() {
  6. return name;
  7. }
  8.  
  9. public void setName(String name) {
  10. this.name = name;
  11. }
  12.  
  13. public double[] getGrades() {
  14. return grades;
  15. }
  16.  
  17. public void setGrades(double[] grades) {
  18. this.grades = grades;
  19. }
  20.  
  21. public Student(String name, double[] grades) {
  22. this.name = name;
  23. this.grades = grades;
  24. }
  25. }
  26.  
  27.  
  28. import java.util.*;
  29.  
  30. public class AverageGrades {
  31.  
  32. public static void main(String[] args) {
  33. Scanner scanner = new Scanner(System.in);
  34.  
  35. int linesCount = Integer.parseInt(scanner.nextLine());
  36. ArrayList<Student> students = new ArrayList<>();
  37.  
  38. for (int i = 0; i < linesCount; i++) {
  39. String data = scanner.nextLine();
  40. System.out.println(data);
  41.  
  42. String name = data.split(" ")[0];
  43. data = data.replace(name + " ", "");
  44. double[] grades = Arrays.stream(data.split(" ")).mapToDouble(Double::parseDouble).toArray();
  45.  
  46. Student currentStudent = new Student(name,grades);
  47. students.add(currentStudent);
  48. }
  49.  
  50. Comparator<Student> nameComparator = (s1, s2) -> (s1.getName() + s1.getGrades().toString()).compareTo((s2.getName() + s2.getGrades().toString()));
  51. students.sort(nameComparator);
  52.  
  53. for(Student student : students) {
  54. if(Arrays.stream(student.getGrades()).average().getAsDouble() >= 5.00) {
  55. String s = String.format("%.2f", Arrays.stream(student.getGrades()).average().getAsDouble()).replace(",", ".") ;
  56. System.out.printf("%s -> %s\n",student.getName(), s);// Arrays.stream(s.getGrades()).average().getAsDouble());
  57. }
  58. }
  59. }
  60. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(28,0): error CS1525: Unexpected symbol `import'
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty