001package edu.pdx.cs410J.grader.gradebook;
002
003public enum LetterGrade {
004
005  A("A"),
006  A_MINUS("A-"),
007  B_PLUS("B+"),
008  B("B"),
009  B_MINUS("B-"),
010  C_PLUS("C+"),
011  C("C"),
012  C_MINUS("C-"),
013  D_PLUS("D+"),
014  D("D"),
015  D_MINUS("D-"),
016  F("F"),
017  I("I", false),
018  X("X", false)
019  ;
020
021  private final String stringValue;
022  private final boolean hasNumericRange;
023
024  LetterGrade(String stringValue) {
025    this(stringValue, true);
026  }
027
028  LetterGrade(String stringValue, boolean hasNumericRange) {
029    this.stringValue = stringValue;
030    this.hasNumericRange = hasNumericRange;
031  }
032
033  public static LetterGrade fromString(String string) {
034    for (LetterGrade grade : values()) {
035      if (grade.asString().equals(string)) {
036        return grade;
037      }
038    }
039
040    throw new IllegalArgumentException("Could not find LetterGrade for string \"" + string + "\"");
041  }
042
043  public String asString() {
044    return stringValue;
045  }
046
047  public String toString() {
048    return asString();
049  }
050
051  public boolean hasNumericRange() {
052    return this.hasNumericRange;
053  }
054}