Created
March 27, 2021 06:16
-
-
Save zapkub/888084652cafbae969cb1d13e951c992 to your computer and use it in GitHub Desktop.
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
package com.company; | |
// สร้างโปรแกรมที่สามารถ วาด * ออกมาเป็นรูป เลขาคณิต 3 แบบ | |
// - สี่เหลี่ยมจตุรัส | |
// - สามเหลี่ยม | |
// - ข้าวหลามตัด | |
// โดยที่มี input เป็น int ที่ 0 < n < 20 | |
class Shape { | |
public String output = ""; | |
} | |
class DotShape extends Shape { | |
public void draw(int size) { | |
int centerpos = (size - 1 ) / 2; | |
for (int i = 0; i < size; i ++) { | |
if (i == centerpos) { | |
this.output = this.output + "*"; | |
} else { | |
this.output = this.output + "_"; | |
} | |
} | |
} | |
} | |
class Renderer { | |
public void Render(Shape shape) { | |
if (shape == null ) { | |
System.out.println("ERROR SHAPE IS NULL"); | |
} else { | |
System.out.println(shape.output); | |
} | |
} | |
} | |
public class Main { | |
public static void main(String[] args) { | |
int input = 5; // Odd number only | |
String shapeType = "DIAMOND"; // DOT, RECT, TRI, DIAMOND | |
Renderer renderer = new Renderer(); | |
Shape shape = null; | |
if (shapeType == "DOT") { | |
DotShape dotshape = new DotShape(); | |
dotshape.draw(input); | |
shape = dotshape; | |
} | |
renderer.Render(shape); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment