This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextPattern.java
80 lines (67 loc) · 2.42 KB
/
TextPattern.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package Projects.P00;
public class TextPattern {
public final static int INTRO = 0, PANEL = 1, H_EMPTY = 2, CHAR_LIM = 3, INV_INP = 4, CRIPT = 5, G_BYE = 6;
public static String getMsg(int idx) {
String msg = "";
switch (idx) {
case INTRO:
msg = "J_ CRIPTOGRAPHY SYSTEM ~~~~~~~~~~~~~~~~\n"
+ "~~~~~~~~~~~~~~~~~~~~~~ by David Santana";
break;
case PANEL:
msg = " CRIPTOGRAPHY SYSTEM \n"
+ " ------------------- \n"
+ "> [1] Encrypt Text \n"
+ "> [2] Show History \n"
+ "> [3] Statistical Queries\n"
+ "> [0] End Application \n";
break;
case H_EMPTY:
msg = "The History is Empty!";
break;
case CHAR_LIM:
msg = String.format("The Character Limit is %d!", Cryptography.CHAR_LIM);
break;
case INV_INP:
msg = "Invalid Input!";
break;
case CRIPT:
msg = "CRIPTOGRAPHY";
break;
case G_BYE:
msg = "String goodBye = \"Good Bye\";";
}
return formatText(msg);
}
public static String formatText(String text) {
String[] strArray = text.split("\n");
int maxLenght = maxLenght(strArray);
String format = "| %-" + maxLenght + "s |";
String hyphens = "|-" + "-".repeat(maxLenght) + "-|";
String formatedText = "";
for (String str : strArray) {
formatedText += String.format(format, str) + '\n';
}
return (hyphens + "\n" + formatedText + hyphens);
}
public static String[] hyphens(int titleLenght, int textLenght) {
String[] hyphens = new String[2];
if (textLenght > titleLenght) {
hyphens[0] = " " + "-".repeat(textLenght - (titleLenght + 1));
hyphens[1] = "-".repeat(textLenght);
} else {
hyphens[0] = "";
hyphens[1] = "-".repeat(titleLenght);
}
return hyphens;
}
public static int maxLenght(String[] strArray) {
int maxLenght = 0;
for (String str : strArray) {
if (str.length() > maxLenght) {
maxLenght = str.length();
}
}
return maxLenght;
}
}