summaryrefslogtreecommitdiff
path: root/src/Q8/Communication.java
blob: cc217e3e1f56ce366785a64291a2cbebe3eb0bcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
 * 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<Communication> {
  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");
  }
}