154 lines
2.5 KiB
Java
154 lines
2.5 KiB
Java
public class DiamondDeluxe{
|
|
|
|
private int n,i,j,k;
|
|
private boolean b;
|
|
|
|
//Konstuktor
|
|
DiamondDeluxe(int n){
|
|
this.n = n;
|
|
this.b = false; //Übergabeparameter
|
|
}
|
|
|
|
|
|
public DiamondDeluxe cut(){
|
|
|
|
//Wenn Größe = 1, passiert nüscht
|
|
if (n == 1){
|
|
this.n = n;
|
|
}
|
|
|
|
//Verkleinern um 2
|
|
else {
|
|
this.n = this.n - 2;
|
|
}
|
|
|
|
|
|
return this;
|
|
}
|
|
|
|
|
|
public DiamondDeluxe setBorder(boolean b){
|
|
|
|
//b in this.b speichern für mit oder ohne Rand
|
|
this.b = b;
|
|
return this;
|
|
}
|
|
|
|
public DiamondDeluxe print(){
|
|
if (b){
|
|
//ooooooooooooooooooooo
|
|
for (i = 0; i < n; i++){
|
|
System.out.print("o");
|
|
}
|
|
}
|
|
|
|
//______________________________________Obere Hälfte Diamant________________________________________
|
|
|
|
int z = 1; // Zähler für "*"
|
|
int g = (n-3)/2; // Obere Hälfte + Mitte
|
|
|
|
//bis n/2 weil es nur obere Hälfte
|
|
for (j = 0; j < n/2; j++ ){
|
|
|
|
if (b){
|
|
//Erste stelle o
|
|
System.out.print("\no");
|
|
}
|
|
else{System.out.println();}
|
|
|
|
//Punktausgabe
|
|
for (k = 0; k < g; k++){
|
|
System.out.print(".");
|
|
}
|
|
//Ausgabe Stern
|
|
for (i = 0; i < z; i ++){
|
|
System.out.print("*");
|
|
}
|
|
//Zähler +2 wil immer 2 Sternchen mehr
|
|
z = z+2;
|
|
for (k = 0; k < g; k++){
|
|
System.out.print(".");
|
|
}
|
|
|
|
//letztes o
|
|
if (b){
|
|
System.out.print("o");
|
|
}
|
|
g--;
|
|
|
|
}
|
|
|
|
//______________________________________Untere Hälfte Diamant________________________________________
|
|
|
|
z = 1; //Zähler für "."
|
|
g = n-4; //-4 wegen o am Rand und Mitte ist schon
|
|
|
|
//bis n/2-1 weil die midde is oben schon
|
|
for (j = 0; j < n/2-1; j++ ){
|
|
|
|
if (b){
|
|
System.out.print("\no");
|
|
}
|
|
else{System.out.println();}
|
|
|
|
|
|
for (i = 0; i < z; i ++){
|
|
System.out.print(".");
|
|
}
|
|
|
|
for (k = 0; k < g; k++){
|
|
System.out.print("*");
|
|
}
|
|
g = g-2;
|
|
|
|
for (i = 0; i < z; i ++){
|
|
System.out.print(".");
|
|
}
|
|
|
|
if (b){
|
|
System.out.print("o");
|
|
}
|
|
z++;
|
|
}
|
|
|
|
//Letzte Reihe ooooooooo
|
|
if (b){
|
|
System.out.println();
|
|
for (i = 0; i < n; i++){
|
|
System.out.print("o");
|
|
}
|
|
}
|
|
|
|
System.out.println();
|
|
|
|
|
|
//______________________________________Quasten mit/ohne Rand_________________________________________
|
|
|
|
//Mit (+1)
|
|
if (b){
|
|
int x = (n+1)/2;
|
|
for (i = 0; i < x; i++){
|
|
System.out.print("| ");
|
|
}
|
|
System.out.println();
|
|
for (i = 0; i < x; i++){
|
|
System.out.print("X ");
|
|
}
|
|
}
|
|
|
|
//ohne (-1)
|
|
else{
|
|
int x = (n-1)/2;
|
|
for (i = 0; i < x; i++){
|
|
System.out.print("| ");
|
|
}
|
|
System.out.println();
|
|
for (i = 0; i < x; i++){
|
|
System.out.print("X ");
|
|
}
|
|
}
|
|
|
|
|
|
return new DiamondDeluxe(n);
|
|
}
|
|
} |