Last active
August 29, 2015 14:12
-
-
Save ralfw/e78a3269a0af94f8a7b5 to your computer and use it in GitHub Desktop.
Weihnachtskata 2014 - Tannenbaum
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
/** | |
* Created by ralfw on 24.12.14. | |
* Coding Dojo der CCD SchooL: http://ccd-school.de/coding-dojo/ | |
* Kata-Beschreibung: https://app.box.com/files/0/f/885439646/1/f_15903236703 | |
*/ | |
class Display { | |
void ausgeben(String text) { | |
println text | |
} | |
} | |
class Tannenbaum { | |
private int _höhe; | |
Tannenbaum(int höhe) { | |
_höhe = höhe; | |
} | |
private String[] Äste_herrichten() { | |
List<String> äste = [] | |
def breite = 1 | |
(1.._höhe).forEach({i -> | |
def ast = "".padRight(breite, "X") | |
ast = "".padRight(_höhe-i, " ") + ast | |
äste.add(ast) | |
breite += 2 | |
}) | |
return äste.toArray() | |
} | |
private String Stamm_schnitzen() { | |
return "".padRight(_höhe-1, " ") + "I" | |
} | |
private String zusammenstecken(String[] äste, String stamm) { | |
return String.join("\n", äste) + "\n$stamm" | |
} | |
String bauen() { | |
def äste = Äste_herrichten() | |
def stamm = Stamm_schnitzen() | |
return zusammenstecken(äste, stamm) | |
} | |
} | |
def display = new Display() | |
def t = new Tannenbaum(5) | |
def baum = t.bauen() | |
display.ausgeben(baum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ein bisschen overengineert, aber dafür habe ich etwas über Groovy und IntelliJ gelernt :-)