dm6801

Subscriber

Dec 17th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. package subscribers;
  2.  
  3. import java.util.Comparator;
  4.  
  5. public abstract class Subscriber implements Comparator<Subscriber> {
  6.     protected static int idCounter = 0;
  7.     protected int id;
  8.     protected String name;
  9.  
  10.    
  11.     public void setID() {
  12.         idCounter += 1;
  13.        
  14.         this.id = idCounter;
  15.     }
  16.     public int getID( ) {
  17.         return id;
  18.     }
  19.    
  20.     public void setName(String name) {
  21.         this.name = name;
  22.     }
  23.     public String getName() {
  24.         return name;
  25.     }
  26.    
  27.    
  28.     public Subscriber(String name) {
  29.         setID();
  30.         setName(name);
  31.     }
  32.    
  33.     @Override
  34.     public String toString() {
  35.         return String.format("(%s::%h)\tname=%s\t\tid=%d",
  36.                             this.getClass().getName(), this, name, id);
  37.     }
  38.    
  39.     @Override
  40.     public int compare(Subscriber s1, Subscriber s2) {
  41.         return s1.getName().compareTo(s2.getName());
  42.     }
  43. }
Add Comment
Please, Sign In to add comment