Created
October 11, 2021 07:26
-
-
Save Khuirul-Huda/755bef78b31840cc302702cea45d999e to your computer and use it in GitHub Desktop.
Simple Text Repeater
This file contains 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.Scanner; | |
public class TextRepeater { | |
private String bunga; | |
private int jumlah; | |
private boolean barisbaru; | |
private String tmp; | |
public static void main(String args[]) { | |
welcome(); | |
Scanner gemas = new Scanner(System.in); | |
TextRepeater huda = new TextRepeater(); | |
out("Enter Text:"); | |
huda.setText(gemas.nextLine()); | |
out("Repeat Count:"); | |
huda.repeatCount(gemas.nextInt()); | |
out("Repeat Mode:"); | |
out("[0] One Line"); | |
out("[1] New Line"); | |
out("Answer:"); | |
huda.newLine(convertBoolean(gemas.nextInt())); | |
huda.verify(huda.newLine()); | |
huda.clear(); | |
out(huda.result()); | |
} | |
private void verify(boolean nya) { | |
if (nya) { | |
bunga = bunga+System.getProperty("line.separator"); | |
} | |
} | |
private boolean newLine() { | |
return this.barisbaru; | |
} | |
private void setText(String bunga) { | |
this.bunga = bunga; | |
} | |
private void repeatCount(int jumlah) { | |
this.jumlah = jumlah; | |
} | |
private void newLine(boolean barisbaru) { | |
this.barisbaru = barisbaru; | |
} | |
private String result() { | |
tmp = new String(new char[jumlah]).replace("\0", bunga); | |
return this.tmp; | |
} | |
public static boolean convertBoolean(int cantik) { | |
boolean sayang = (cantik == 0 ) ? false : true; | |
return sayang; | |
} | |
public static void out(String flower) { | |
System.out.println(flower); | |
} | |
public static void welcome() { | |
out("Simple TextRepater using Java"); | |
System.out.println(System.getProperty("line.separator")); | |
} | |
private void clear() { | |
try { | |
Runtime.getRuntime().exec("clear"); | |
Runtime.getRuntime().exec("clsr"); | |
} catch (Exception e) { | |
//np | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment