Commit da87bfb1 authored by mahoffmann's avatar mahoffmann
Browse files

added Übung OOP 3und4 "Boot"

parent c380ee0c
......@@ -33,7 +33,7 @@ public class Dice {
public void showHistory() {
for (int i = 0; i <= counter; i++) {
System.out.println("Wurf #" + i + " mit dem Wert: " + rollHistory[i]);
System.out.println("Wurf #" + (i+1) + " mit dem Wert: " + rollHistory[i]);
}
}
}
package referenzdatentypen;
public class Boot implements Cloneable {
String name;
String farbe;
public Boot(){
}
public Boot(String name, String farbe) {
this.name = name;
this.farbe = farbe;
}
public Boot clone() {
Boot copy = new Boot(name, farbe);
return copy;
}
}
package referenzdatentypen;
import javax.swing.plaf.synth.SynthMenuBarUI;
public class Programm {
public static void main(String[] args) {
Werkstatt werkstatt = new Werkstatt();
Boot boot1 = new Boot("Titanic", "ROT");
Boot boot2 = boot1;
Boot boot3 = boot1.clone();
System.out.println("Boot 1: " + boot1.name + "; " + boot1.farbe);
werkstatt.setColor(boot2,"SCHWARZ");
werkstatt.setColor(boot3,"GRUEN");
System.out.println("Boot 1: " + boot1.name + "; " + boot1.farbe);
System.out.println("Boot 2: " + boot2.name + "; " + boot2.farbe);
System.out.println("Boot 3: " + boot3.name + "; " + boot3.farbe);
}
}
package referenzdatentypen;
public class Werkstatt {
public void setColor(Boot boot, String neueFarbe) {
boot.farbe = neueFarbe;
}
}
Markdown is supported
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