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
/
Main.java
128 lines (110 loc) · 3.24 KB
/
Main.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package Projects.P00;
import java.lang.Thread;
import java.util.Scanner;
public class Main {
private static final String C = "Crypt.", H = "History", SQ = "Stat. Queries";
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int maxLenght = 0, lettersTyped = 0;
String history = "";
print(TextPattern.getMsg(TextPattern.INTRO) + "\n", 0);
boolean endApp = false;
while (!endApp) {
print(TextPattern.getMsg(TextPattern.PANEL) + "\n" + "_Operation: ", 1);
String operation = input.nextLine();
switch (operation) {
case "0":
endApp = true;
print(TextPattern.getMsg(TextPattern.G_BYE), 2);
break;
case "1":
print(TextPattern.getMsg(TextPattern.CRIPT), 1);
boolean validText = false;
while (!validText) {
print("_Text: ", 1);
String text = input.nextLine();
if (text.length() <= Cryptography.CHAR_LIM) {
char[] characteres = text.toCharArray();
if (haveLetter(characteres)) {
validText = true;
String encryptedText = Cryptography.encryptText(text);
String[] hps = TextPattern.hyphens(C.length(), encryptedText.length());
lettersTyped += letterCount(characteres);
history += "\nT_: " + text + "\nC_: " + encryptedText + "\n";
if (maxLenght < encryptedText.length()) {
maxLenght = encryptedText.length();
}
print(C + hps[0], 2);
charByChar(encryptedText);
print(hps[1], 2);
} else {
print(TextPattern.getMsg(TextPattern.INV_INP), 2);
}
} else {
print(TextPattern.getMsg(TextPattern.CHAR_LIM), 2);
}
}
break;
case "2":
if (history != "") {
String[] hps = TextPattern.hyphens(H.length(), (maxLenght + 4));
print(H + hps[0], 1);
print(history, 1);
print(hps[1], 2);
} else {
print(TextPattern.getMsg(TextPattern.H_EMPTY), 2);
}
break;
case "3":
if (history != "") {
String queries[] = { "Letters Typed_: " + lettersTyped,
"Total Characters of Biggest Text_: " + maxLenght };
String[] hps = TextPattern.hyphens(SQ.length(), queries[1].length());
print(SQ + hps[0], 1);
print(queries[0] + "\n" + queries[1], 1);
print(hps[1], 2);
} else {
print(TextPattern.getMsg(TextPattern.H_EMPTY), 2);
}
break;
default:
print(TextPattern.getMsg(TextPattern.INV_INP), 2);
}
}
input.close();
}
private static void print(String text, int blankSpace) {
if (blankSpace == 0) {
System.out.print(text);
} else if (blankSpace == 1) {
System.out.print("\n" + text);
} else {
System.out.print("\n" + text + "\n");
}
}
private static void charByChar(String text) {
for (char character : text.toCharArray()) {
try {
Thread.sleep(90);
} catch (InterruptedException e) {}
System.out.print(character);
}
}
private static int letterCount(char[] characteres) {
int letterQtt = 0;
for (char character : characteres) {
if (Character.isLetter(character)) {
letterQtt++;
}
}
return letterQtt;
}
private static boolean haveLetter(char[] characteres) {
for (char character : characteres) {
if (Character.isLetter(character)) {
return true;
}
}
return false;
}
}