I'm pretty new to Java and following a course for it. So here goes my super stupid question probably. Suppose I have class with an enum like this:
public class Diamant implements Comparable<Diamant> {
final private String stockNr;
final private double karaat;
final private String helderheid;
final private char kleur;
final private String snede;
public Diamant(String stockNr, double karaat, String helderheid, char kleur, String cut) {
this.stockNr = stockNr;
this.karaat = karaat;
this.helderheid = helderheid;
this.kleur = kleur;
this.snede = cut;
}
public String getStockNummer() {
return stockNr;
}
public double getKaraat() {
return karaat;
}
public String getHelderheid() {
return helderheid;
}
public char getKleur() {
return kleur;
}
public String getSnede() {
return snede;
}
enum Color {
D(0), E(1), F(2), G(3), H(4), I(5), J(6), K(7), L(8), M(9), N(10), O(11),
P(12), Q(13), R(14), S(15), T(16), U(17), V(18), W(19), X(20), Y(21), Z(22);
int quality;
Color(int quality) {
this.quality = quality;
}
public int getQuality() {
return quality;
}
}
enum Brightness {
FL(0), IF(1), VVS1(2), VVS2(3), VS1(4), VS2(5), SI1(6), SI2(7), I1(8), I2(9), I3(10);
int quality;
Brightness(int quality) {
this.quality = quality;
}
public int getQuality() {
return quality;
}
}
@Override
public String toString() {
return "StockNr='" + getStockNummer() + "\t" +
" Karaat=" + getKaraat() + "\t" +
" Helderheid='" + getHelderheid() + "\t" +
" Kleur=" + getKleur() + "\t";
}
@Override
public int compareTo(Diamant other) {
//Sort according to Karaat (Max=5.0)
if (this.getKaraat() < other.getKaraat()) {
return 1;
} else if (this.getKaraat() > other.getKaraat()) {
return -1;
} else {
// Sort according to Kleur first then Helderheid
Color.D.getQuality();
(this.getKleur()).getQuality();
if (this.getKleur() < other.getKleur()) {
return 1;
} else if (this.getKleur() > other.getKleur()) {
return -1;
} else {
return 0;
}
}
}
How is it possible to use the method getQuality without explicitly typing the enum value in the CompareTo. In other words, this works fine:
Color.D.getQuality();
However, this doesn't work (although the method getKleur returns D to):
Color.(this.getKleur()).getQuality();
How can I work with the enum method getQuality() without hard typing the letter?
this.getKleur().getQuality()(I'm assumingthis.getKleur()returns aColor)getKleurreturnsD, but is it aColor.Dor a"D"String?