ppupil2

Student

Nov 17th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package model;
  7.  
  8. /**
  9.  *
  10.  * @author phuon
  11.  */
  12. public class Student implements Comparable<Student> {
  13.  
  14.     private String id;
  15.     private String name;
  16.     private int semester;
  17.     private String courseName;
  18.  
  19.     public Student(String id, String name, int semester, String courseName) {
  20.         this.id = id;
  21.         this.name = name;
  22.         this.semester = semester;
  23.         this.courseName = courseName;
  24.     }
  25.  
  26.     public String getSearchResult() {
  27.         String lineFormat = "%-21s%10s%13s";
  28.         return String.format(lineFormat, name, semester, courseName);
  29.     }
  30.  
  31.     @Override
  32.     public int compareTo(Student rhs) {
  33.         if (this.id.equals(rhs.id)) {
  34.             if (this.semester == rhs.semester) {
  35.                 return this.courseName.compareTo(rhs.courseName);
  36.             }
  37.             return this.semester - rhs.semester;
  38.         }
  39.         return this.id.compareTo(rhs.id);
  40.     }
  41.  
  42.     public String getId() {
  43.         return id;
  44.     }
  45.  
  46.     public void setId(String id) {
  47.         this.id = id;
  48.     }
  49.  
  50.     public String getName() {
  51.         return name;
  52.     }
  53.  
  54.     public void setName(String name) {
  55.         this.name = name;
  56.     }
  57.  
  58.     public int getSemester() {
  59.         return semester;
  60.     }
  61.  
  62.     public void setSemester(int semester) {
  63.         this.semester = semester;
  64.     }
  65.  
  66.     public String getCourseName() {
  67.         return courseName;
  68.     }
  69.  
  70.     public void setCourseName(String courseName) {
  71.         this.courseName = courseName;
  72.     }
  73. }
  74.  
Add Comment
Please, Sign In to add comment