-
Notifications
You must be signed in to change notification settings - Fork 0
/
TypingTutor_keyMonarch.java
299 lines (242 loc) · 11.8 KB
/
TypingTutor_keyMonarch.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Random;
class TutorWorking{
static class ProgressTracker{
int timesProgressSaved;
boolean[] toAddSpace = new boolean[10];
ArrayList<Integer> listProgress = new ArrayList<>(3);
ArrayList<Integer> listProgressWPM = new ArrayList<>(3);
void progressGraphPrinter(){
StringBuffer[] a = new StringBuffer[10];
for (int i = 0; i < 10; i++) {
a[i] = new StringBuffer();
}
for (int i = 1; i < 10; i++) {
a[i].append((char)(i+65)).append(" class -| ");
}
a[0].append("\t 0 *------------------------------------> Time");
for (Integer progress : listProgress) {
graphPlotter(a, progress);
}
graphPrinter(a);
}
private void graphPrinter(StringBuffer[] sbToPrint){
if(listProgress.isEmpty()) System.out.println("Please Save Your Progress !");
else {
for (int i = 9; i >= 0; i--) {
System.out.println(sbToPrint[i]);
}
}
}
private void graphPlotter(StringBuffer[] a , int x){
a[x].append(" ".repeat(timesProgressSaved)).append("*");
timesProgressSaved++;
}
void addProgress(int iGetProgress){
listProgress.add(iGetProgress);
System.out.println("Progress Saved Successfully!!");
}
void showProgress(){
System.out.println("---------- Progress Chart ----------");
if(listProgress.isEmpty()){
System.out.println("Please Save Your Progress");
}else {
for (int i = 0; i < listProgress.size(); i++) {
System.out.println((i+1)+".Entry\t\t\t\t Adjusted WPM "+(listProgressWPM.get(i)));
}
}
}
}
ProgressTracker progressTracker = new ProgressTracker();
void displayTips(){
System.out.println("---------------- TIPS SECTION ----------------");
System.out.println("""
1. Use the correct starting position. When practicing your typing skills,
it's important to use proper hand placement.
""");
System.out.println("2. Maintain good posture and do not look Down your hands\n");
System.out.println("3. Keep at least 45 - 70 cm of distance between your eyes and the screen\n");
System.out.println("4. Face the screen with your head slightly tilted forward\n");
}
void speedChecker() {
Scanner sc = new Scanner(System.in);
Random rand = new Random();
String[] sPara = new String[3];
sPara[0] = "Amidst the cosmic symphony, Earth's vibrant stories unfold. From serene landscapes to bustling cities,\n" +
"human threads weave tales of triumph and tribulation, contributing to the grand narrative of existence.";
sPara[1] = "Beneath the celestial canopy, Earth spins tales of resilience and beauty. Nature's wonders and\n" +
"human endeavors intertwine, creating a narrative of diversity and harmony in the grand cosmic tableau.";
sPara[2] = "In the cosmic theater, Earth plays its part with breathtaking landscapes and human stories.\n" +
"From sunlit meadows to urban skylines, diverse experiences merge into a captivating narrative across the cosmic stage.";
System.out.println("Please Be Ready For a Quick Speed Test .....\n"+"+".repeat(45)+"\n");
try {
Thread.sleep(1500);
} catch (Exception e) {
e.printStackTrace();
}
int iRand = rand.nextInt(3);
System.out.println(sPara[iRand]);
System.out.println("\n"+"+".repeat(45));
UserInterfaceTutor.printMsgWithProgressBar("Loading Speed Test : Press Enter To Submit the Test");
System.out.println("\n\t\t\tPlease Start Typing");
long startTime = System.currentTimeMillis();
String sUserInput = sc.nextLine();
long endTime = System.currentTimeMillis();
int[] iArrData = getWords(sPara, sUserInput, iRand);
int iWords = iArrData[2];
int iLettersPos = iArrData[3];
int iLettersNeg = iArrData[0];
int iTotalLetters = iArrData[1];
float WPM = ((float) iWords * 60 ) / ((endTime-startTime)/1000F);
int ACCURACY = (iLettersPos*100)/(iTotalLetters);
System.out.println("Your Typing Speed Comes Near About "+(WPM)+" WPM");
System.out.println("Your Accuracy is "+(ACCURACY)+"%");
System.out.println("Your Adjusted Typing Speed is "+((WPM * ACCURACY)/100)+"\n\n");
System.out.println("Do you want to SAVE your Progress ? (y/n)");
String sInput = sc.next().trim();
if(sInput.equalsIgnoreCase("Y")){
int toCompare = pointCalculator((int)((WPM * ACCURACY)/100));
progressTracker.addProgress(toCompare);
progressTracker.listProgressWPM.add((int)((WPM * ACCURACY)/100));
}
if(WPM < 18){
System.out.println("Based on your Typing Speed Your Experience comes to be Beginner\n");
}
else if(WPM < 35){
System.out.println("Based on your Typing Speed Your Experience comes to be Basic\n");
}
else if(WPM < 60){
System.out.println("Based on your Typing Speed Your Experience comes to be Intermediate\n");
}
else{
System.out.println("Based on your Typing Speed Your Experience comes to be Advance\n");
}
}
private int pointCalculator(int WPM){
if(WPM < 15) return 1;
else if(WPM < 30) return 2;
else if(WPM < 45) return 3;
else if(WPM < 60) return 4;
else if(WPM < 75) return 5;
else if(WPM < 90) return 6;
else if(WPM < 105) return 7;
else if(WPM < 120) return 8;
else return 9;
}
private int[] getWords(String[] sPara, String sUserInput, int iRand) {
String[][] sParaArr = {sPara[0].split(" ") , sPara[1].split(" ") , sPara[2].split(" ")};
String[] sInputArr = sUserInput.split(" ");
int iWords = 0;
int iLettersPos = 0;
int iLettersNeg = 0;
int iTotalLetters = 0;
int j;
for (int i = 0; i < sInputArr.length; i++) {
int minToUse = Math.min(sInputArr[i].length(),sParaArr[iRand][i].length());
for (j = 0; j < minToUse; j++) {
if(sInputArr[i].charAt(j) == sParaArr[iRand][i].charAt(j)){
iLettersPos++;
iTotalLetters++;
}else{
iLettersNeg++;
iTotalLetters++;
}
}
if (j == sInputArr[i].length()){
if (iLettersPos > iLettersNeg){
iWords++;
}
}
}
return new int[]{iLettersNeg , iTotalLetters , iWords, iLettersPos};
}
}
class UserInterfaceTutor{
static void welcomePage(){
Scanner sc = new Scanner(System.in);
logoPrinter();
try {
Thread.sleep(2000);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("\t\tWelcome to KEYmonarch : A User friendly Java based Tutor to teach Touch Typing\n");
boolean toProceed = true;
TutorWorking tFunc = new TutorWorking();
while(toProceed){
int iInput = getiInput(sc);
switch(iInput){
case 1 -> tFunc.speedChecker();
case 2 -> tFunc.displayTips();
case 3 -> tFunc.progressTracker.progressGraphPrinter();
case 4 -> tFunc.progressTracker.showProgress();
case 5 -> toProceed = false;
}
}
}
private static int getiInput(Scanner sc) {
System.out.println("++++++++ : Please Select From The menu : +++++++++");
System.out.println("1. Typing Test \t\t3. progress Tracking Graph");
System.out.println("2. Typing Tips \t\t4. Progress");
System.out.println("5. EXIT...");
System.out.println("----------------------------------------------");
System.out.print("Your Choice : ");
return sc.nextInt();
}
static void logoPrinter(){
String[] str2 = {
" __ __ ________ __ __ __",
" | \\ / \\ \\ \\ / \\ | \\",
" | ▓▓ / ▓▓ ▓▓▓▓▓▓▓▓\\▓▓\\ / ▓▓______ ____ ______ _______ ______ ______ _______| ▓▓____",
" | ▓▓/ ▓▓| ▓▓__ \\▓▓\\/ ▓▓| \\ \\ / \\| \\ | \\ / \\ / \\ ▓▓ \\",
" | ▓▓ ▓▓ | ▓▓ \\ \\▓▓ ▓▓ | ▓▓▓▓▓▓\\▓▓▓▓\\ ▓▓▓▓▓▓\\ ▓▓▓▓▓▓▓\\ \\▓▓▓▓▓▓\\ ▓▓▓▓▓▓\\ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓\\",
" | ▓▓▓▓▓\\ | ▓▓▓▓▓ \\▓▓▓▓ | ▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ ▓▓ | ▓▓/ ▓▓ ▓▓ \\▓▓ ▓▓ | ▓▓ | ▓▓",
" | ▓▓ \\▓▓\\| ▓▓_____ | ▓▓ | ▓▓ | ▓▓ | ▓▓ ▓▓__/ ▓▓ ▓▓ | ▓▓ ▓▓▓▓▓▓▓ ▓▓ | ▓▓_____| ▓▓ | ▓▓",
" | ▓▓ \\▓▓\\ ▓▓ \\ | ▓▓ | ▓▓ | ▓▓ | ▓▓\\▓▓ ▓▓ ▓▓ | ▓▓\\▓▓ ▓▓ ▓▓ \\▓▓ \\ ▓▓ | ▓▓",
" \\▓▓ \\▓▓\\▓▓▓▓▓▓▓▓ \\▓▓ \\▓▓ \\▓▓ \\▓▓ \\▓▓▓▓▓▓ \\▓▓ \\▓▓ \\▓▓▓▓▓▓▓\\▓▓ \\▓▓▓▓▓▓▓\\▓▓ \\▓▓\n",
"========================================================================================================",
"========================================================================================================"
};
for (String lToPrint : str2){
System.out.println(lToPrint);
}
}
static void printMsgWithProgressBar(String sMsg){
int totalTasks = 100;
int currentTask = 0;
int progressBarWidth = 41;
System.out.println(sMsg);
StringBuffer progressStringBuffer = new StringBuffer();
progressStringBuffer.append(" ".repeat(progressBarWidth));
while (currentTask <= totalTasks) {
int progress = (int) (currentTask / (float) totalTasks * progressBarWidth);
StringBuffer progressBarBuffer = new StringBuffer(progressBarWidth + 10);
progressBarBuffer.append('[');
for (int i = 0; i < progressBarWidth; i++) {
if (i < progress) {
progressBarBuffer.append('=');
} else if (i == progress) {
progressBarBuffer.append('>');
} else {
progressBarBuffer.append(' ');
}
}
progressBarBuffer.append("] ").append(progress * 100 / progressBarWidth).append('%');
String progressBarWithBuffer = progressBarBuffer.toString();
System.out.print("\r" + progressBarWithBuffer);
try {
Thread.sleep(50);
} catch (Exception e) {
e.printStackTrace();
}
currentTask++;
}
}
}
public class TypingTutorProject {
public static void main(String[] args) {
TutorWorking.ProgressTracker p = new TutorWorking.ProgressTracker();
UserInterfaceTutor.welcomePage();
}
}