Skip to content

Instantly share code, notes, and snippets.

@ralfw
Last active August 29, 2015 14:12
Show Gist options
  • Save ralfw/e78a3269a0af94f8a7b5 to your computer and use it in GitHub Desktop.
Save ralfw/e78a3269a0af94f8a7b5 to your computer and use it in GitHub Desktop.
Weihnachtskata 2014 - Tannenbaum
/**
* 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)
@ralfw
Copy link
Author

ralfw commented Dec 24, 2014

Ein bisschen overengineert, aber dafür habe ich etwas über Groovy und IntelliJ gelernt :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment