/** * Assignment 1, COMP268 Class: Communication.java * * @description Represents a candidates communication ability. * @author: mo khan Student ID: 3431709 * @date May 8, 2019 * @version 1.0 */ package Q8; public class Communication implements Comparable { private String name; private Integer ranking; /** * Constructs a Communication object. * * @param name the name of the communication level * @param ranking the ranking of the communication level. */ public Communication(String name, Integer ranking) { this.name = name; this.ranking = ranking; } /** * Compares one communication level with another. * * @param other the other communication level to compare against * @return a negative integer, zero, or a positive integer as this object is less than, equal to, * or greater than the specified object. */ public int compareTo(Communication other) { return this.ranking.compareTo(other.ranking); } /** * Compares one communication level with another. * * @param other the other communication level to compare against * @return true if this communication level is equal to or better than the other. */ public boolean isAtLeast(Communication other) { return this.compareTo(other) >= 0; } /** * The string representation of the candidate. * * @return the name of the candidate */ @Override public String toString() { return this.name; } public static final Communication Poor = new Communication("poor", 0); public static final Communication Average = new Communication("average", 1); public static final Communication Excellent = new Communication("excellent", 2); /** * @param name of the communication level to find. * @return the Communication level matching the name */ public static Communication findBy(String name) { switch (name) { case "poor": return Communication.Poor; case "average": return Communication.Average; case "excellent": return Communication.Excellent; } throw new IllegalArgumentException("Unknown communication type"); } }