SHARE
TWEET

Untitled

a guest Oct 20th, 2019 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         Student [] student = {s};
  15.        
  16.         for (int i = 0; i < numStudents ; i++) {
  17.             System.out.println("\nSTUDENT " + (i+1));
  18.             student[i].firstName = Console.getString("Last Name: ");
  19.             student[i].lastName = Console.getString("First Name: ");
  20.             student[i].score = Console.getString("Score: ");
  21.         }
  22.        
  23.         System.out.println("\nSummary");
  24.         System.out.printf(s.firstName, s.lastName, s.score);
  25.     }
  26. }
  27.  
  28.  
  29.  
  30. // student.java
  31.  
  32. public class Student implements Comparable<Student> {
  33.     String lastName;
  34.     String firstName;
  35.     String score;
  36.    
  37.     public Student() {
  38.         super();
  39.     }
  40.  
  41.     public Student(String lastName, String firstName, String score) {
  42.         super();
  43.         this.lastName = lastName;
  44.         this.firstName = firstName;
  45.         this.score = score;
  46.     }
  47.  
  48.     @Override
  49.     public int compareTo(Student o) {
  50.         int last = this.lastName.compareTo(o.lastName);
  51.         return last == 0 ? this.firstName.compareTo(o.firstName) : last;
  52.     }  
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top