Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // StudentScores.java
- import java.util.ArrayList;
- import java.util.Collections;
- public class StudentScores {
- public static void main(String[] args) {
- System.out.println("The Student Scores Application\n");
- int numStudents = Console.getInt("Number of students: ");
- Student s = new Student();
- String [] student = {s.lastName, s.firstName, s.score};
- for (int i = 0; i < numStudents ; i++) {
- System.out.println("\nSTUDENT " + (i+1));
- student[i] = Console.getString("Last Name: ");
- student[i] = Console.getString("First Name: ");
- student[i] = Console.getString("Score: ");
- }
- System.out.println("\nSummary");
- System.out.println(student);
- }
- }
- // Student.java
- public class Student implements Comparable<Student> {
- String lastName;
- String firstName;
- String score;
- public Student() {
- super();
- }
- public Student(String lastName, String firstName, String score) {
- super();
- this.lastName = lastName;
- this.firstName = firstName;
- this.score = score;
- }
- @Override
- public int compareTo(Student o) {
- int last = this.lastName.compareTo(o.lastName);
- return last == 0 ? this.firstName.compareTo(o.firstName) : last;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement