Created
October 23, 2018 12:47
-
-
Save nea89o/6361aca8311158d1bcc775c8e3628b94 to your computer and use it in GitHub Desktop.
Komposition created by romangraef - https://repl.it/@romangraef/Komposition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Futter { | |
String name; | |
float mass; | |
public Futter(String name) { | |
this.name = name; | |
this.mass = 100f; | |
} | |
public String toString(){ | |
return "Futter: "+name + ", "+mass+"g."; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Optional; | |
class Futternapf { | |
Optional<Futter> futter; | |
public Futternapf() { | |
futter = Optional.empty(); | |
} | |
public void refillFutter(String name) { | |
futter = Optional.of(new Futter(name)); | |
} | |
public String toString() { | |
return "Futternapf. Futter: "+futter; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Main { | |
public static void main(String[] args) { | |
Futternapf f = new Futternapf(); | |
System.out.println(f); | |
f.refillFutter("Premium Futter"); | |
System.out.println(f); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment