Advertisement
ppupil2

Report

Nov 17th, 2020
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 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 Report implements Comparable<Report> {
  13.  
  14.     private String studentName;
  15.     private String courseName;
  16.     private int totalOfCourses;
  17.  
  18.     public Report(String studentName, String courseName, int totalOfCourses) {
  19.         this.studentName = studentName;
  20.         this.courseName = courseName;
  21.         this.totalOfCourses = totalOfCourses;
  22.     }
  23.  
  24.     @Override
  25.     public String toString() {
  26.         String lineFormat = "%-21s%12s%18s";
  27.         return String.format(lineFormat, studentName, courseName, totalOfCourses);
  28.     }
  29.  
  30.     @Override
  31.     public int compareTo(Report rhs) {
  32.         if (this.studentName.equals(rhs.studentName)) {
  33.             if (this.courseName.equals(rhs.courseName)) {
  34.                 return this.totalOfCourses - rhs.totalOfCourses;
  35.             }
  36.             return this.courseName.compareTo(rhs.courseName);
  37.         }
  38.         return this.studentName.compareTo(rhs.studentName);
  39.     }
  40.  
  41.     public String getStudentName() {
  42.         return studentName;
  43.     }
  44.  
  45.     public void setStudentName(String studentName) {
  46.         this.studentName = studentName;
  47.     }
  48.  
  49.     public String getCourseName() {
  50.         return courseName;
  51.     }
  52.  
  53.     public void setCourseName(String courseName) {
  54.         this.courseName = courseName;
  55.     }
  56.  
  57.     public int getTotalOfCourses() {
  58.         return totalOfCourses;
  59.     }
  60.  
  61.     public void setTotalOfCourses(int totalOfCourses) {
  62.         this.totalOfCourses = totalOfCourses;
  63.     }
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement