Kapitel 8: "Verwendung von Bibliotheken"

"DoubleListe.java"


public class DoubleListe {
double liste[];

public DoubleListe(int num) {
liste = new double[num];
}

public String toString() {
StringBuffer sb = new StringBuffer();
int i;
sb.append("DoubleListe[");
for (i = 0; i < liste.length - 1; i++)
sb.append(liste[i] + ",");
if (i < liste.length)
sb.append(liste[i]);
sb.append("]");
return sb.toString();
}

public boolean equals(Object obj) {
if (obj instanceof DoubleListe) {
DoubleListe dl = (DoubleListe) obj;

if (dl.liste.length != this.liste.length)
return false;

for (int i=0; i < this.liste.length; i++) {
if (dl.liste[i] != this.liste[i])
return false;
}
return true;
}
return false;
}

public static void main(String[] args) {
DoubleListe d1, d2;

d1 = new DoubleListe(Integer.parseInt(args[0]));
d2 = new DoubleListe(Integer.parseInt(args[0]));

System.out.println(d1);
System.out.println(d2);

if (!d1.equals(d2))
System.err.println("Unterschiedliche Listen!");
else
System.out.println("Gleiche Listen!");
}
}

Picksel Media Marco Block © 2006-2009 – ImpressumKontakt
Gestaltung und Umsetzung Tobias Losch, www.picksel-media.de