testDiff.java
Třída, která zjistí vzdálenost
java
public class testDiff {
private Double x, y;
public static void main(String[] args) {
boolean assertsEnabled = false;
assert assertsEnabled = true;
if (!assertsEnabled) {
throw new RuntimeException("Assert se zapíná parametrem -ea");
}
testDiff a = new testDiff(2.0,3.0);
testDiff b = new testDiff(5.0,7.0);
assert 5 == a.diff(b) : "Má být 5, vyšlo " + a.diff(b);
testDiff c = new testDiff(7.0,15.0);
assert 13 == a.diff(c) : "Má být 13, vyšlo " + a.diff(c);
}
public testDiff(Double x, Double y) {
this.x = x;
this.y = y;
}
public Double diff(testDiff sour) {
Double xx = this.x - sour.x;
Double yy = this.y - sour.y;
return Math.sqrt(xx*xx + yy*yy);
}
}
Neformátovaný
Přidáno: 4.1.2013
Expirace: Neuvedeno