binibiningtinamoran

Team

Nov 4th, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. public class Team implements Comparable <Team> {
  2.  
  3.     private String name;
  4.  
  5.     public Team() {
  6.         this.name = "";
  7.     }
  8.  
  9.     public Team(String userName) {
  10.         this.name = userName;
  11.     }
  12.  
  13.     public String getName() {
  14.         return name;
  15.     }
  16.  
  17.     public void setName(String userName) {
  18.         this.name = userName;
  19.     }
  20.  
  21.     public String toString() {
  22.         return "The name is: " + name;
  23.     }
  24.  
  25.     @Override
  26.     public boolean equals(Object other) {
  27.         if (other instanceof Team) {
  28.             Team that = (Team) other;
  29.  
  30.             return this.name.equalsIgnoreCase(that.name);
  31.         } else {
  32.             return false;
  33.         }
  34.     }
  35.  
  36.     @Override
  37.     public int compareTo(Team other) {
  38.         return this.getName().compareToIgnoreCase(other.getName());
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment