Commit ff8d6666 authored by matthias's avatar matthias
Browse files

added Übung "Lok_Waggon" in OOP3_4

parent bf41c9af
......@@ -9,6 +9,7 @@ public class Lok {
public Lok(int lokNummer) {
this.lokNummer = lokNummer;
naechsterWagon = null;
}
@Override
......@@ -34,6 +35,7 @@ public class Lok {
Lok lok = (Lok) obj;
if (lokNummer != lokNummer) {
return false;
} else return true;
} return naechsterWagon != null ?
naechsterWagon.equals(lok.naechsterWagon) : lok.naechsterWagon == null;
}
}
package lok_waggon;
public class Programm {
final static int WAGONS = 5;
public static void main(String[] args) {
Lok lok1 = new Lok(1);
lok1.naechsterWagon = new Wagon(1, 500, 1000);
Wagon wagon = lok1.naechsterWagon;
......@@ -14,32 +10,20 @@ public class Programm {
wagon.naechsterWagon = new Wagon(i, 500, 1000);
wagon = wagon.naechsterWagon;
}
printZug(lok1);
Lok lok2 = lok1.clone();
printZug(lok2);
wagon = lok1.naechsterWagon;
while (wagon.getWagonNummer() != 4) {
wagon = wagon.naechsterWagon;
}
wagon.naechsterWagon = null;
printZug(lok1);
printZug(lok2);
System.out.println("Vergleich von Lok#1 und Lok#2 ist: " + lok1.equals(lok2));
Lok lok3 = lok1.clone();
System.out.println("Vergleich von Lok#3 und Lok#1 ist: " + lok3.equals(lok1));
}
private static void printZug(Lok lok) {
System.out.print(lok + " <=> ");
Wagon wagon = lok.naechsterWagon;
......@@ -49,4 +33,4 @@ public class Programm {
}
System.out.println();
}
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment