Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. // StudentScores.java
  2.  
  3. import java.util.ArrayList;  
  4. import java.util.Collections;
  5. public class StudentScores {
  6.  
  7.     public static void main(String[] args) {
  8.         System.out.println("The Student Scores Application\n");
  9.        
  10.         int numStudents = Console.getInt("Number of students: ");
  11.        
  12.         Student s = new Student();
  13.        
  14.         String [] student = {s.lastName, s.firstName, s.score};
  15.        
  16.         for (int i = 0; i < numStudents ; i++) {
  17.             System.out.println("\nSTUDENT " + (i+1));
  18.            
  19.             student[i] = Console.getString("Last Name: ");
  20.             student[i] = Console.getString("First Name: ");
  21.             student[i] = Console.getString("Score: ");
  22.         }
  23.        
  24.         System.out.println("\nSummary");
  25.         System.out.println(student);
  26.     }
  27. }
  28.  
  29.  
  30.  
  31. // Student.java
  32.  
  33. public class Student implements Comparable<Student> {
  34.     String lastName;
  35.     String firstName;
  36.     String score;
  37.    
  38.     public Student() {
  39.         super();
  40.     }
  41.  
  42.     public Student(String lastName, String firstName, String score) {
  43.         super();
  44.         this.lastName = lastName;
  45.         this.firstName = firstName;
  46.         this.score = score;
  47.     }
  48.  
  49.     @Override
  50.     public int compareTo(Student o) {
  51.         int last = this.lastName.compareTo(o.lastName);
  52.         return last == 0 ? this.firstName.compareTo(o.firstName) : last;
  53.     }  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement