Student.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Stores student id and last name in a sortable way.
  3. *
  4. * Project 4
  5. *
  6. * @author Thomas Flucke tflucke
  7. * @author Lara Luu ljluu
  8. *
  9. * @since 2015/11/12
  10. */
  11. public class Student
  12. {
  13. /**
  14. * The student's id
  15. */
  16. private long id;
  17. /**
  18. * The student's last name
  19. */
  20. private String lastName;
  21. /**
  22. * Creates a new student object with he given id and last name
  23. * @param id The student's id number
  24. * @param lastName The student's last name
  25. */
  26. public Student(long id, String lastName)
  27. {
  28. this.id = id;
  29. this.lastName = lastName;
  30. }
  31. @Override
  32. public boolean equals(Object other)
  33. {
  34. return other instanceof Student && id == ((Student) other).id;
  35. }
  36. /**
  37. * Creates a hashcode representation for the student object.
  38. * The hashcode will be taken from the student's ID number.
  39. * @return long type student id
  40. */
  41. @Override
  42. public int hashCode()
  43. {
  44. return new Long(id).hashCode();
  45. }
  46. /**
  47. * Creates a string representation of the student object.
  48. * The string will be in the format: "{ id: [id], name: [last name] }".
  49. * @return The string representation of the student.
  50. */
  51. @Override
  52. public String toString()
  53. {
  54. return String.format("{ id: %d, name: %s }", this.id, this.lastName);
  55. }
  56. }