Files
courses/2025_Praxis_der_Programmierung/PairComparable.java
T
2025-07-30 15:57:48 +02:00

42 lines
841 B
Java

public class PairComparable<X extends Number & Comparable<X>, Y extends Number>
implements Comparable<PairComparable<X, Y>> {
private X first;
private Y second;
public PairComparable(X first, Y second) {
this.first = first;
this.second = second;
}
public X getFirst() {
return first;
}
public void setFirst(X first) {
this.first = first;
}
public Y getSecond() {
return second;
}
public void setSecond(Y second) {
this.second = second;
}
@Override
public int compareTo(PairComparable<X, Y> other) {
double thisFraction = this.first.doubleValue() / this.second.doubleValue();
double otherFraction = other.first.doubleValue() / other.second.doubleValue();
return Double.compare(thisFraction, otherFraction);
}
@Override
public String toString() {
return "(" + first + ", " + second + ")";
}
}