title: comparing two strings in java - compareTo
body: <p>I keep getting Exception in thread "main" java.lang.ClassCastException: studentscoresapp.Student cannot be cast to java.lang.Comparable am not able to figure out why. Maybe someone can take a look and tell me where I am messing up. I have been messing with it for hours and it seems that I am making the program worse and nothing I have found online seems to work. Thanks</p>
  
  <pre><code>public class Student implements IComparable&lt;Student&gt;
  {
      private String lastName;
      private String firstName;
      private int score;
  
      public Student(String lastName, String firstName, int score)
      {
          this.lastName = lastName;
          this.firstName = firstName;
          this.score = score;
      }
  
      /**
       * @return the lastName
       */
      public String getLastName() {
          return lastName;
      }
  
      /**
       * @param lastName the lastName to set
       */
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      /**
       * @return the firstName
       */
      public String getFirstName() {
          return firstName;
      }
  
      /**
       * @param firstName the firstName to set
       */
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      /**
       * @return the score
       */
      public int getScore() {
          return score;
      }
  
      /**
       * @param score the score to set
       */
      public void setScore(int score) {
      this.score = score;
      }
  
      @Override
      public int compareTo(Object obj)
          {
          Student i = (Student) obj;
          if (i.lastName.equals(lastName)) {
              return firstName.compareToIgnoreCase(i.firstName);
          } else {
              return lastName.compareToIgnoreCase(i.lastName);
          }
      }
  
  }
  </code></pre>
  
  <p>My interface for compareTo override</p>
  
  <pre><code>public interface IComparable&lt;E&gt; {
      int compareTo(Object object);
  }
  </code></pre>
  
  <p>and the student score app</p>
  
  <pre><code>public class StudentScoresApp {
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
          // Welcome message
          System.out.println("Welcome to the Student Scores Application.");
          System.out.println();
          int count = ConsoleValidator.getInt("Enter number of students to enter: ", 0);
          Student[] student = new Student[count];
          for (int j = 0; count &gt; j; j++)
          {
              student[j] = getItem();
              System.out.println();
          }
          Arrays.sort(student);
          for (Student i : student)
          {
              System.out.println(i.getLastName() + " " + i.getFirstName() + ": " + i.getScore() + "\n");
          }
      }
      public static Student getItem()
      {
          String name = ConsoleValidator.getString("Student first name: ");
          String last = ConsoleValidator.getString("Student last name: ");
          int score = ConsoleValidator.getInt("Student score: ", 0);
          Student j = new Student(name,last,score);
          return j;
  }
  </code></pre>
  
  <p>}</p>