-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCh5_MindReader.html
More file actions
979 lines (970 loc) · 53.1 KB
/
Ch5_MindReader.html
File metadata and controls
979 lines (970 loc) · 53.1 KB
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript: Ch5 MindReader</title>
<meta name="title" content="Variations on a Theme: JavaScript: Ch5 MindReader">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="UTF-8">
<meta name="description" content="An object-oriented Introduction">
<meta name="keywords" content="JavaScript,object orientation,introduction">
<meta name="author" content="Ralph P. Lano">
<meta name="robots" content="index,follow">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="book.css">
</head>
<body>
<center>
<div id="wrap">
<ul class="sidenav">
<p><a href="../index.html">Variations on a Theme</a><a href="index.html">JavaScript</a></p>
<li><a href="Ch1_Karel.html">Karel</a></li>
<li><a href="Ch2_Graphics.html">Graphics</a></li>
<li><a href="Ch3_Console.html">Console</a></li>
<li><a href="Ch4_Agrar.html">Agrar</a></li>
<li><a href="Ch5_MindReader.html">MindReader</a></li>
<li><a href="Ch6_Swing.html">Swing</a></li>
<li><a href="Ch7_Asteroids.html">Asteroids</a></li>
<li><a href="Ch8_Stocks.html">Stocks</a></li>
<li><a href="index.html"> </a></li>
<li><a href="AppA_Primer.html">Primer</a></li>
<li><a href="AppB_Libraries.html">Libraries</a></li>
<li><a href="AppC_Ideas.html">Ideas</a></li>
</ul>
<div class="content">
<p>
<img alt="" src="img/b6b4d73c-045b-41e8-9aa4-02379366993d.png" style="display: block; margin-left: auto; margin-right: auto;width: 325px; height: 262px;" /></p>
<h1>
MindReader</h1>
<p>
In this chapter we return to console programs. We will learn about text and word processing, that is how to use characters and strings. In addition, we will also deepen our understanding of classes. We will see how classes are structured and we will create our own classes.</p>
<p>
.</p>
<h2>
<img alt="" src="img/3252a125-0883-496a-88cd-8183ff7af75d.png" style="margin-left: 10px; margin-right: 10px; width: 186px; height: 60px; float: right;" />String</h2>
<p>
Strings are made up of zero or more characters. A character can be a letters, a digits or a special character. The apostrophes (single or double quotes) are necessary to distinguish digits from numbers:</p>
<pre style="margin-left: 40px;">
let x = 42;
let z = "42";
</pre>
<p>
The first line declares the number 42, the second line the string "42". Special characters are characters like '.', '$', etc., but there are also invisible characters such as '\n' for a new line or '\t' for a tab.</p>
<p>
Let's continue with a few examples:</p>
<pre style="margin-left: 40px;">
let s1 = "Hello";
let s2 = "world";</pre>
<p>
Here we declare two strings, s1 and s2, and initialize them to the values "Hello" and "world". Strings can contain none, one or many characters:</p>
<pre style="margin-left: 40px;">
let s3 = "!";
let s4 = " ";
let s5 = "";</pre>
<p>
Here s3 contains an exclamation mark. s4 also contains a character, the space. s5 contains no character at all, but s5 is still a string.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Ch5_MindReader/stringExample" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/stringExample.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<p>
What makes strings really interesting is that we can make new strings out of old ones by concatenating them:</p>
<pre style="margin-left: 40px;">
s6 = s1 + s4 + s2 + s3;</pre>
<p>
and also print them</p>
<pre style="margin-left: 40px;">
println( s6 );</pre>
<p>
And just as we can read numbers (int and double) from the console, we can also read strings from the console:</p>
<pre style="margin-left: 40px;">
let name = readLine("Enter your name: ");</pre>
<p>
The String class has a few useful functions:</p>
<ul>
<li>
<strong>length:</strong> returns the number of characters in a string,</li>
<li>
<strong>charAt(pos):</strong> returns the character at the position pos,</li>
<li>
<strong>substring(p1):</strong> returns the substring from position p1 to the end of the string,</li>
<li>
<strong>substring(p1, p2):</strong> returns the substring from position p1 to position p2, but without the character at position p2,</li>
<li>
<strong>includes(s):</strong> returns true if the string s is contained in the string,</li>
<li>
<strong>indexOf(s):</strong> determines if the string s is contained in the string, if it is it returns the position of the character, -1 otherwise,</li>
<li>
<strong>trim():</strong> removes white spaces at the beginning and end of a string, and</li>
<li>
<strong>toUpperCase():</strong> returns the uppercase version of a string, of course there is also a toLowerCase().</li>
</ul>
<p>
As we will see in a moment, there are quite a few things we can do with these functions.</p>
<p>
.</p>
<h2>
Exercise: Print the Characters of a String</h2>
<p>
As a first example, we iterate through the characters of a string and display them one by one on the console:</p>
<pre style="margin-left: 40px;">
let s1 = "Hello";
for (let i=0; i<s1.length; i++) {
let c = s1.charAt( i );
println( c );
}
</pre>
<p>
.</p>
<h2>
Exercise: Reverse a String</h2>
<p>
We can use what we just learned to reverse a string:</p>
<pre style="margin-left: 40px;">
let s1 = "stressed";
let s2 = "";
for ( let i=0; i<s1.length; i++) {
let c = s1.charAt( i );
s2 = c + s2;
}
println( s2 );
</pre>
<p>
The word "stressed" becomes the word "desserts". Words that remain the same when reversed, such as "racecar" or "otto", are called palindromes.</p>
<p>
.</p>
<h2>
Exercise: Compare two Strings</h2>
<p>
Next, we want to determine whether two strings are equal. In JavaScript we can use the "==" operator for this:</p>
<pre style="margin-left: 40px;">
let s1 = "Hello ";
let s2 = s1 + "world";
let s3 = "Hello world";
if (s2 == s3) {
println("Equal");
} else {
println("Not Equal");
}</pre>
<p>
As expected "Equal" is what gets prinited here. Just for curiosity, what happens if we compare numbers and strings:</p>
<pre style="margin-left: 40px;">
let x = 42;
let y = "42";
if (x == y) {
console.log("x and y are equal");
}
if (x <span style="color:#0000ff;">===</span> y) {
console.log("x and y are exactly equal");
}</pre>
<p>
When we use the simple equality operator "==", JavaScript says they are equal. However, there is also the exactly equals operator "===" with three equal signs, and in that case they are not longer equal. The difference is that the exactly equal operator also checks if the two variables are of the same type.</p>
<p>
<strong>SEP: Always use the exactly equals operator "===" when comparing variables.</strong></p>
<p>
.</p>
<h2>
Exercise: Cut a String</h2>
<p>
As a last little exercise, we want to cut a string into two pieces. For this we use the functions indexOf() and substring():</p>
<pre style="margin-left: 40px;">
let s1 = "Hello world";
let posSpace = s1.indexOf(" ");
let s2 = s1.substring(0, posSpace);
let s3 = s1.substring(posSpace);
println(s2);
println(s3);</pre>
<p>
We find the position of the space using the indexOf() function. Then we cut off the front part with the substring() function. Two things are important here: the first character is at position 0, i.e. as usual we start counting at 0. And the character at the posSpace position is not included. Finally, we cut off the rest, and store it in s3.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Ch5_MindReader/stringTokenizerExample" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/stringTokenizerExample.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
StringTokenizer</h2>
<p>
Cutting strings into pieces is a very common task. That is why there is a special class for this, the StringTokenizer:</p>
<pre style="margin-left: 40px;">
let sentence = "hi there what's up?";
let toki = new StringTokenizer(sentence, " .,?");
while (toki.hasMoreTokens()) {
println(toki.nextToken());
}</pre>
<p>
First, we initialize the StringTokenizer by telling it what it should cut apart (sentence), and how it should cut it. That means we tell it the separators it should use, like ' ', '.', ',' or '?', for instance. The StringTokenizer then splits the string into tokens, i.e., words. To get to these words, we ask the StringTokenizer if it has any tokens, so we call the hasMoreTokens() function. If it has any, we ask the StringTokenizer to give us the next token using nextToken(). We do this until all the tokens are used up.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Ch5_MindReader/immutability" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/immutability.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
Immutability</h2>
<p>
Something that sometimes leads to confusion is the immutability of strings. Immutability means that a string cannot be changed. Let's take a look at an example:</p>
<pre style="margin-left: 40px;">
let s1 = "Hello";
s1.toUpperCase();
println(s1);
</pre>
<p>
What is displayed on the console? "Hello" is displayed, and not, as one might hope, "HELLO". This has to do with the fact that strings are unchangeable, i.e. immutable.</p>
<p>
But there is a trick to changing strings anyways: we simply assign a new value to them:</p>
<pre style="margin-left: 40px;">
let s1 = "Hello";
<span style="color:#0000ff;">s1 = </span>s1.toUpperCase();
println(s1);
</pre>
<p>
.</p>
<h2>
Classes</h2>
<p>
We have already heard a lot about classes, and we have used them many times, e.g. the Karel class or the graphic classes like GRect and GOval. Also, in this chapter we used the String class and the StringTokenizer class. The question that arises is: can we make our own classes?</p>
<p>
Of course, and it's not that hard. As a first example, we look at a student from the perspective of a university. What information would a university need to know about a student? If we limit ourselves to the essentials, then these are name, matriculation number and credit points (ECTS). We take these attributes of a student and combine them into a class:</p>
<pre style="margin-left: 40px;">
class Student {
constructor(_name, _id, _credits) {
this.name = _name;
this.id = _id;
this.credits = _credits;
}
}
</pre>
<p>
In principle, a class is nothing more than a data container. Each class should be saved in its own file, the name of the file should be the same as the name of the class with a '.js' extension.</p>
<p>
<strong><strong>SEP: Class names should always start with capital letters and follow the CamelCase convention.</strong></strong></p>
<p>
.</p>
<h2>
Constructor</h2>
<p>
Classes are 'intelligent' data containers. This means that they not only contain and bundle the data, but also initialize, manage and change it. So they also do something with the data, and classes have functions for that. Usually, we call functions that belong to classes <em>methods</em>, to distinguish them from the normal functions. The most important method is the constructor, which initializes the data.</p>
<pre style="margin-left: 40px;">
class Student {
<span style="color:#0000ff;">constructor(_name, _id, _credits)</span> {
this.name = _name;
this.id = _id;
this.credits = _credits;
}
}</pre>
<p>
The constructor, like any function, can have parameters. A constructor never returns a value, because it is implicitely assumed, what it returns is an <em>instance</em> of that class.</p>
<p>
Now we have a class, how do we use it? We use them like any other class. Let's write a console program which creates an instance of our Student class:</p>
<pre style="margin-left: 40px;">
async function setup() {
...
let fritz = <span style="color:#0000ff;">new</span> Student("Fritz", 12345, 0.0);
println(fritz.name + ", " + fritz.id + ", " + fritz.credits);
}
</pre>
<p>
We create a new instance of the class Student. This instance (also called object) we call fritz. To create the object we have to call the constructor with "new". We initialize the instance variables of the class: that is, name is initialized to the value "Fritz", id to the value 12345, and credits to the value 0.0.</p>
<p>
.</p>
<h2>
Methods</h2>
<p>
Let's say we want to print this information about fritz quite often. Then every time, we would have to write the above print statement. However, if we create a method called toString(),</p>
<pre style="margin-left: 40px;">
class Student {
...
toString() {
return "Student [name=" + this.name + ", id=" + this.id
+ ", credits=" + this.credits + "]";
}
}</pre>
<p>
then printing is much easier:</p>
<pre style="margin-left: 40px;">
async function setup() {
...
println(fritz.toString());
}
</pre>
<p>
</p>
<p>
Another example is incrementing credits. Fritz has been studying hard, passed his Programming exam, and now he wants he credits updated:</p>
<pre style="margin-left: 40px;">
fritz.credits = fritz.credits + 5;</pre>
<p>
More convenient would be an incrementCredits() method:</p>
<pre style="margin-left: 40px;">
fritz.incrementCredits(5);</pre>
<p>
This is more for convenience, but makes our code more readable.</p>
<p>
<strong>SEP: Every class should have a toString() method.</strong></p>
<p>
.</p>
<h2>
Closures</h2>
<p>
Now notice, we can read fritz's name, but we can also change it:</p>
<pre style="margin-left: 40px;">
println(fritz.name);
fritz.name = "Hans";
println(fritz.name);</pre>
<p>
JavaScript is pretty open about accessing the instance variables of a class. Sometimes you are fine with that, but sometimes you don't want this.</p>
<p>
Consider the following class, where we added a method named <em>getId()</em>:</p>
<pre style="margin-left: 40px;">
class Student {
constructor(_name, _id, _credits) {
this.name = _name;
this.credits = _credits;
<span style="color:#0000ff;"> // closure: read only
this.getId = (function () {
let id = _id;
return function () {
return id
}
})();</span>
}
}
</pre>
<p>
It looks very strange, but it does what we wanted: we can read the <em>id</em>, but we can no longer change it:</p>
<pre style="margin-left: 40px;">
let fritz = new Student("Fritz", 12345, 0.0);
println(fritz.getId()); // 12345
fritz.id = 42;
println(fritz.getId()); // 12345</pre>
<p>
JavaScript just ignores the assignment. Closures are kind of complicated, and we will not use them often. But you know now, that they exist.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Ch5_MindReader/student" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/student.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
Exercise: Hansel und Gretel</h2>
<p>
The class Student is now ready for use and as an example we take a look at the two students Hansel and Gretel at the Brothers Grimm college:</p>
<pre style="margin-left: 40px;">
async function setup() {
createConsole();
let hansel = new Student("Hänschen", 12345, 0.0);
println(hansel.name);
let gretel = new Student("Gretel", 54321, 11.0);
println(gretel.name);
gretel.name = "Gretchen";
gretel.incrementCredits(5);
println(gretel.toString());
}
</pre>
<p>
.</p>
<h2>
Type Conversion</h2>
<p>
JavaScript has a few functions for converting between strings and numbers. It is not uncommon that we have to convert a string into a number. </p>
<pre style="margin-left: 40px;">
let x = parseInt("42");
let y = parseFloat("42.0");
</pre>
<p>
Sometimes we also want to convert a floating point number into an integer number:</p>
<pre style="margin-left: 40px;">
let z = Math.trunc(42.0);
</pre>
<p>
Conversely, to create a string from a number, you can use a little trick:</p>
<pre style="margin-left: 40px;">
let x = 42;
let fourtyTwo = "" + x;</pre>
<p>
There is also other ways, but knowing one is fine.</p>
<p>
.</p>
<hr />
<h1>
Review</h1>
<p>
In this chapter we have mainly dealt with strings and classes. Also, it is the first time we've written our own class. We have seen that a class has variables and methods. Sometimes we also call the variables instance variables, class properties, or class attributes. We have seen that methods always do something, and that there is a special method, the constructor. We also learned about the String and StringTokenizer classes.</p>
<p>
.</p>
<hr />
<h1>
Projects</h1>
<p>
The projects in this chapter mainly deal with strings and writing simple classes.</p>
<p>
.</p>
<h2>
Student</h2>
<p>
In the example for Student the question arises why are the instance variables private? Let us look at the problem from the other side. Suppose instance variables were public: could we then prevent a student from getting negative credits, or that her id could be changed?</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/ascii" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/ascii.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
ASCII</h2>
<p>
To store characters internally the computer uses numbers. This means we can add and subtract these characters just like numbers, and we can even use them in conditions and loops. For example, to determine if a character is an uppercase letter, you can use the following condition:</p>
<pre style="margin-left: 40px;">
if (c >= 'A' && c <= 'Z') { ... } </pre>
<p>
Or to turn a lowercase letter into an uppercase letter, we can use the following trick:</p>
<pre style="margin-left: 40px;">
let klein = 'd';
let gross = klein.toUpperCase();</pre>
<p>
You can also make ints out of chars and vice versa via a cast, that is a type conversion</p>
<pre style="margin-left: 40px;">
let char = String.fromCharCode(i);
print(char);
</pre>
<p>
With this knowledge we want to write the following three functions:</p>
<ul>
<li>
isUpperCase(char c)</li>
<li>
toUpperCase(char c)</li>
<li>
printASCIITable()</li>
</ul>
<p>
As for the latter, it is sufficient to output the ASCII characters between 32 and 128, since the first 31 ASCII characters cannot be printed.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/passwordCreator" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/passwordCreator.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
PasswordCreator</h2>
<p>
With our knowledge of strings we can now write a password generator. A good password should be at least 8 characters long and contain at least one lowercase letter, one uppercase letter, one digit and one symbol. So we could define four strings containing the possible characters, and then use the RandomGenerator to randomly select two of them and put them together to a password, for example:</p>
<pre style="margin-left: 40px;">
const small = "abcdefghijklmnopqrstuvwxyz";
let password = "";
password += small.charAt(rgen.nextInt(small.length));
...
</pre>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/randomText" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/randomText.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
RandomText</h2>
<p>
For test purposes it is sometimes helpful to be able to generate random text. That's not so hard. We start again with the top-down approach. Let's assume we have a function createRandomSentence() that generates a random sentence. Then we could create a random text by simply creating several random sentences. The createRandomSentence() function, in turn, is easy if we assume there is a function called createRandomWord(), because then we would just take somewhere between three and five words, put spaces between them and add a period at the end. Also the createRandomWord() function is not that difficult, because words consist of lower case letters, and have a length of about 3 to 8 letters, so</p>
<pre style="margin-left: 40px;">
function createRandomWord() {
let word = "";
let nrOfCharsInWord = rgen.nextInt(3, 8);
for (let i = 0; i < nrOfCharsInWord; i++) {
word += String.fromCharCode('a'.charCodeAt(0) + rgen.nextInt(26));
}
return word;
}</pre>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/palindrome" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/palindrome.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
Palindrome</h2>
<p>
Words that remain the same when reversed, such as "racecar" or "pensioner", are also called palindromes. We want to write a function called isPalindrome(String s), which determines if a string is a palindrome. To do this, we write a function reverse() that reverses a given string, and then compare the original with the reversed string using equals(). If both are equal, it is a palindrome.</p>
<p>
.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/countUpperCase" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/countUpperCase.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
CountUpperCase</h2>
<p>
Here we should write a function that counts the uppercase letters in a string. This can be very useful, for example, if you want to determine whether a certain text is German or English: English text has on average less capital letters per sentence. We can either use the character class or the function we wrote above.</p>
<p>
.</p>
<p>
.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/readOneChar" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/readOneChar.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
ReadOneChar</h2>
<p>
We want the user to be able to enter only one letter. The user should not be able to enter zero or more than one letter, but only exactly one letter. Therefore we want to write a function readOneChar(), which returns one char as return value.</p>
<p>
There is the readString() function for reading strings. Hence, we use the loop-and-a-half, and use as abort criterion that the string read should be of length one.</p>
<pre style="margin-left: 40px;">
while (true) {
s = await readLine(msg);
if (s.length == 1)
break;
println("Please, only enter one character:");
}</pre>
<p>
.</p>
<h2>
<img alt="" src="img/bdedbd5d-3b32-412e-9bcc-fccde618d3bb.png" style="margin-left: 10px; margin-right: 10px; width: 200px; height: 203px; float: right;" />Encrypt</h2>
<p>
Another interesting application that we can now easily implement is a small encryption program. We use the so-called Caesar cipher, named after Julius Caesar [2]. To encrypt a text using Caesar's cipher, the letters in a given text are simply shifted by a fixed number, the key. For example, if the key is four, then an 'a' becomes an 'e', a 'b' becomes an 'f', etc. To decrypt, the process is simply reversed.</p>
<p>
To implement this in code, we write two functions, encrypt() and decrypt(), one for encrypting, the other for decrypting. Both take two parameters, a string and an int, the key. One returns the encrypted text as a string, the other returns the decrypted text.</p>
<p>
.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/encrypt" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/encrypt.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<p>
.</p>
<p>
Note: in order not to make it too complicated, it makes sense to convert the text to lower case before starting the encryption. And the remainder operator '%' is very practical here:</p>
<pre style="margin-left: 40px;">
function encryptChar(c, key) {
let d = c.charCodeAt(0) - 'a'.charCodeAt(0);
let e = d + key;
let f = e % 26;
let g = String.fromCharCode(f + 'a'.charCodeAt(0));
return g;
}
</pre>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/abjad" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/abjad.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
Abjad</h2>
<p>
Around 1500 B.C. the Phoenicians developed the first alphabet script, a left-hand consonant script. Consonant scripts are writing systems in which only consonants are being used [2].</p>
<p>
To show that such a script actually can be readable, archaeologists have commissioned us to write a console program that removes all vowels from a given text. We can proceed as follows:</p>
<ul>
<li>
with readLine() we ask the user to enter a normal text,</li>
<li>
we then look for vowels and remove them, and</li>
<li>
we then output the result using println().</li>
</ul>
<p>
Ideally we should remember the top-down approach, i.e. we should perhaps assume that the functions removeVowels() and isVowel() exist, and then implement them later. You could also use the replace() function of the String class, but more about this in the next project.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/franconian" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/franconian.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
Franconian</h2>
<p>
The language of the Franks, also called 'lingua franca', has been wrongly forgotten. The 'lingua franca' (Italian for 'Franconian language') is a Romance-based pidgin language. Pidgin language or pidgin refers to a reduced form of language that is used by people of different languages to communicate [3].</p>
<p>
In order to contribute to the understanding of peoples, we should write a German-Franconian translation program. In Franconian the following phonetic simplifications take place (also known as "inner-German weakening of consonants"):</p>
<ul>
<li>
t -> d</li>
<li>
p -> b</li>
<li>
k -> g</li>
</ul>
<p>
For example, the word 'Politiker' (politician) becomes 'Bolidiger' in Franconian.</p>
<p>
So let us write a function translateGermanToFranconian(), which has a string as parameter with the German text, and returns a string, which is the translated Franconian version. For this you could use the replaceAll() function of the String class:</p>
<pre style="margin-left: 40px;">
String german = "politiker";
String franconian = german.replaceAll('t','d');
...
</pre>
<p>
But replaceAll() and also replace() use "regular expressions". So unless you know what those are, you should waiting using them until your second semester. However, a function like the following is all you need:</p>
<pre style="margin-left: 40px;">
function translateChar(c) {
switch (c) {
case 't':
return 'd';
case 'k':
return 'g';
case 'p':
return 'b';
default:
return c;
}
}</pre>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/pigLatin" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/pigLatin.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
PigLatin</h2>
<p>
Pig Latin [5] is a secret language for children that has very simple rules:</p>
<ul>
<li>
if a word begins with a consonant, then the consonant is moved to the end of the word and the syllable "ay" is appended. So "loser" becomes "oserlay" or "button" becomes "uttonbay",</li>
<li>
if a word begins with a vowel, then only the syllable "ay" is appended. So "eagle" becomes "eagleay" and "america" becomes "amercaay".</li>
</ul>
<p>
Hence, we should write another console program that asks the user for an English sentence and then translates it into Pig Latin. Here, too, we should use of the top-down approach.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/yodaTalk" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/yodaTalk.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
YodaTalk</h2>
<p>
In the typology of languages [6], the sentence structure subject-verb-object (SVO), i.e. the subject is in the first place, the verb in the second and the object in the third, occurs very frequently. About 75% of all languages in the world follow this or a very similar pattern. We know that Yoda comes from the swamp planet Dagobah and there the preferred sentence construction is object, subject verb (O,SV).</p>
<p>
For example, the English sentence,</p>
<p style="margin-left: 40px;">
You are lucky.</p>
<p>
translates into "Yodish":</p>
<p style="margin-left: 40px;">
Lucky, you are.</p>
<p>
To simplify interplanetary communication, it is now our task to write a console program that translates a given text from English into Yodish. We can assume that each sentence entered always consists of three words, always in the order SVO.</p>
<p>
Here's what we could do:</p>
<ul>
<li>
we ask the user to enter an English text,</li>
<li>
then we identify the three elements subject, verb and object using a StringTokenizer,</li>
<li>
and using println(), we then output the translated Yodish in the form object, subject verb.</li>
</ul>
<p>
Of course we use the top-down approach again and implement a function called translateFromEnglishToYodish().</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/randomGeneratorTester" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/randomGeneratorTester.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
RandomGenerator</h2>
<p>
We want to write our own RandomGenerator class. This is not so difficult when we know that there is a function called Math.random() in standard JavaScript. This function returns a floating point number between 0 and 1, including 0, but excluding 1. If we want to use it to generate a number between 1 and 6, this is how it works:</p>
<pre style="margin-left: 40px;">
let diceRoll = 1 + (int)(Math.random() * 6);</pre>
<p>
With this knowledge we want to write a class called RandomGenerator, that has the methods nextInt(int a, int b), nextInt(int b), nextBoolean() and nextColor(). In the future we can always use our own class instead of the ACM class, if we want to.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/counter" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/counter.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
Counter</h2>
<p>
We want to create a class Counter that can act as a counter. The class should have a private instance variable called count. In the constructor, this variable is to be set to the value 0. Then there should be a method called getValue(), which simply returns the current value of the variable count. And there should be a method called incrementCounter(), which increases the value of the variable count by one. Can you prevent somebody else from messing with your counter? (Closure)</p>
<p>
.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/pointTester" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/pointTester.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
Point</h2>
<p>
Next we want to write a class Point. This should correspond to a point in two-dimensional space, i.e. have an x and a y coordinate. The class should have a constructor of the form Point(int x, int y), and the methods: getX(), getY(), move(int dx, int dy), equals(Point p), add(Point p), and toString().</p>
<p>
.</p>
<p>
.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/connectTwoMovingPoints" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/connectTwoMovingPoints.png" style="width: 200px; height: 200px; display: block;" />Try it</a></div>
<h2>
ConnectTwoMovingPoints</h2>
<p>
Our class Point seems relatively boring on its own. But if we use it for the motion of two points which are connected by a colored line, then this actually looks quite nice.</p>
<p>
We start with the Point class, which, however, has slightly different requirements than the one of the last project. It should be as simple as possible. It should have four instance variables, namely x, y, vx and vy. The constructor should have no parameters, and it should initialize the instance variables with some small random values. This Point class should have only one method:</p>
<pre style="margin-left: 40px;">
move() {
this.x += this.vx;
this.y += this.vy;
}</pre>
<p>
We want to use this class in our graphics program ConnectTwoMovingPoints:</p>
<pre style="margin-left: 40px;">
let p1;
let p2;
function setup() {
...
p1 = new Point();
p2 = new Point();
}
function draw() {
p1.move();
p2.move();
checkForCollisionWithWall(p1);
checkForCollisionWithWall(p2);
drawConnection(p1, p2);
update();
}</pre>
<p>
In our game loop, we move the two points, check if the points are still in the field, and then connect the two points with a line. That's actually quite simple. However, if you only want to display ten lines at a time and want to delete the older lines again, you need arrays (next chapter).</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/blackjack" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/blackjack.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
Blackjack</h2>
<p>
According to Wikipedia, "Blackjack is the most widely played card game offered in casinos" [9]. We want to implement a slightly simpler version of this game.</p>
<p>
Instead of cards, we simply use numbers, numbers between 1 and 11. The computer plays the dealer and starts by generating a random number between 17 and 25. Then it's the player's turn. She starts with a card, i.e. a random number between 1 and 11, and can then decide whether she wants another card. If yes, another random number between 1 and 11 is generated and added to the current "hand". When the player no longer wishes to have a new card, the "hand" of the player is compared with that of the computer.</p>
<p>
The winner is whoever has 21 or less points and has more than the other player. Otherwise, it's a draw.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/simpleCraps" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/simpleCraps.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
SimpleCraps</h2>
<p>
"Craps or Seven Eleven is a dice game that enjoys great popularity, especially in the USA." [10]</p>
<p>
We will implement a simpler version of Craps: We have just a simple dice. The player starts with credits of 100 Euro. In each round, 10 Euro are bet and the player bets on one of the following outcomes:</p>
<ul>
<li>
odd</li>
<li>
even</li>
<li>
high (4,5,6)</li>
<li>
low (1,2,3)</li>
</ul>
<p>
The game is over when the player has no more credits.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/factorial" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/factorial.png" style="width: 220px; height: 245px; display: block;" />Try it</a></div>
<h2>
Factorial</h2>
<p>
The factorial of a number is the product of all integer numbers less than or equal to that number. For example, the factorial of 3 is:</p>
<pre>
3! = 1 * 2 * 3 = 6</pre>
<p>
We want to write a function called calculateFactorial(int n) which calculates the factorial of the number n. With that function we then want to list the factorials of the numbers from 1 to 20. Probably using a for-loop is a good idea.</p>
<p>
The factorials have the property that they become very large very quickly. And that leads to a problem, because computers do have some problems, when it comes to large numbers! What does JavaScript say when the numbers get to large?</p>
<p>
.</p>
<p>
.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/rabbits" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/rabbits.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
Rabbits</h2>
<p>
Anyone who has ever had rabbits knows that they have an interesting characteristic: they reproduce rapidly (that's why they are called rabbits). To see how rapidly, let us write a program that calculates how our rabbit population develops over the months. We follow the model of Fibonacci [12]:</p>
<ul>
<li>
"Each pair of rabbits throws another pair of rabbits every month.</li>
<li>
A newborn couple only has offspring in the second month of its life (the gestation period of rabbits is about one month).</li>
<li>
All rabbits are in an enclosed space so that no animal can leave the population and none can come in from the outside."</li>
</ul>
<p>
If we write the simulation correctly, then the Fibonacci sequence, i.e. the numbers 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... should come out.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/wordTwist" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/wordTwist.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
WordTwist</h2>
<p>
The WordTwist game is about recognizing a word in which some letters have been swapped. So, for example, we should realize that the word "nhickce" actually originated from the word "chicken".</p>
<p>
We begin with the starting word, e.g. "chicken", and swap some letters. We show this word to the user, and he should then guess which was the original word. If we use the top-down approach again (as we always should). Then it makes sense to write a function scrambleWord(String word) that takes the starting word as parameter and returns the scrambled word as return value. If we continue the top-down approach, it also makes sense to write a function called randomSwap(String word) that simply swaps two random letters in the word. If we call this function several times, the result is a well-shuffled word. What we still need is a function that picks a random word to start with:</p>
<pre style="margin-left: 40px;">
function pickGuessWord() {
let rgen = new RandomGenerator();
switch (rgen.nextInt(0, 3)) {
case 0:
return "dog";
case 1:
return "cat";
default:
return "chicken";
}
}</pre>
<p>
.</p>
<hr />
<h1>
Challenges</h1>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/hangman" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/hangman.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
Hangman</h2>
<p>
Hangman is a simple letter game [12]. Although it is a graphical game originally, we will implement a text-based version here. It starts with the computer picking a random word. The player may then guess one letter at a time. The program then shows whether this letter occurs in the word and if it does, at which position it occurs. This is then repeated until the word has been guessed. At the end the user should see how many attempts were necessary to guess the word. However, only failed attempts are counted.</p>
<p>
We need two instance variables,</p>
<pre style="margin-left: 40px;">
let guessWord;
let hintWord;</pre>
<p>
where guessWord contains the word to be guessed (e.g. "mother") and hintWord contains the letters that were guessed correctly so far, in the beginning it contains only dashes (e.g. "------"). We need to initialize both guessWord and hintWord:</p>
<pre style="margin-left: 40px;">
guessWord = pickGuessWord();
hintWord = createHintWord();</pre>
<p>
where the function pickGuessWord() already exists (see WordTwist above) and we still have to write the function createHintWord().</p>
<p>
After that the game loop starts: In the first step we show the player the hintWord so that she has an idea how many letters the word contains. Then we ask the player to enter a letter. Here we can use the function readOneChar() from the project ReadOneChar. By means of <em>includes()</em>,</p>
<pre style="margin-left: 40px;">
let c = await readChar();
if (guessWord.<span style="color:#0000ff;">includes</span>("" + c)) {
buildNewHintWord(c);
}</pre>
<p>
we can determine if the new letter appears in the guessWord. If yes, we must construct a new hintWord using the buildNewHintWord(c) function. This function should insert the correct letter in the correct place in hintWord, and the new hintWord should then be displayed to the player.</p>
<p>
The abort criterion is relatively simple, if there are no more dashes "-" in the hintWord, then the player has guessed the word. Alternatively we could also compare guessWord and hintWord, if they are equal the game is over.</p>
<p>
.</p>
<div style="display:block; float: right; margin: 10px;">
<a href="./src/tryIt.html?name=Pr5_MindReader/mindReader" style="display: block; text-align: center;" target="_blank"><img alt="" src="img/mindReader.png" style="width: 220px; height: 124px; display: block;" />Try it</a></div>
<h2>
MindReader</h2>
<p>
This game is about mind reading. It is inspired by a coin toss where we have heads and tails. But instead of tossing a coin, the player simply picks either heads or tails. The computer now tries to predict what the player guessed. If the prediction of the computer was correct, the computer receives one point, otherwise the player gets one. Whoever gets 25 points first, wins. The idea of the game is based on a handout by Professor Raja Sooriamurthi, who in turn was inspired by Professor Gregory Rawlins [13].</p>
<p>
If we use the top-down approach, we get the following rough structure for the game:</p>
<ul>
<li>
the computer makes a prediction, either head ('h') or tail ('t') (computerMakePrediction()),</li>
<li>
the player makes his choice, either head or tail (humanMakePick()),</li>
<li>
the prediction of the computer is displayed (revealPrediction()),</li>
<li>
the computers prediction is compared with the selection of the player and depending on whether the computer has guessed correctly or not, either the computer gets a point or the player.</li>
</ul>
<p>
The whole thing is then repeated until either one has reached 25 points.</p>
<p>
For the game we need four instance variables:</p>
<pre style="margin-left: 40px;">
let computerGuess;
let humanGuess;
let computerScore = 0;
let humanScore = 0;
let predictor;</pre>
<p>
The character entered by the player, the character predicted by the computer, as well as the scores, i.e. the player's score and the computer's score.</p>
<p>
We could write our own predictor (see extensions), or we can use the one from Professor Sooriamurthi:</p>
<pre style="margin-left: 40px;">
predictor = new MindReaderPredictor();</pre>
<p>
For this to work we must include the MindReaderPredictor.js file at the beginning of our code with the line:</p>
<pre style="margin-left: 40px;">
include("Pr5_MindReader/mindReaderPredictor.js");</pre>
<p>
The class MindReaderPredictor has two functions, makePrediction() and addNewGuess(char c). The first function tries to make a prediction, so it returns either 'h' or 't'. The second adds a new player guess to the Predictor database, allowing the Predictor to make better predictions. So the Predictor tries to learn from the player.</p>
<p>
Extensions: One can come up with many extensions for this game. e.g.:</p>
<ul>
<li>
you could play several games in a row, but MindReaderPredictor should not be reinitialized each time, or</li>
<li>
you could write your own MindReaderPredictor class, a very simple version would just randomly chooses between 'h' and 't'.</li>
</ul>
<p>
.</p>
<hr />
<h1>
Questions</h1>
<ol>
<li>
Give an example of a class and an example of an object.<br />
</li>
<li>
"arnold" is an "actor". Is "arnold" an object or a class?<br />
</li>
<li>
What is usually the job of a constructor?<br />
</li>
<li>
It is good style to give each class a toString() method. What should the toString() method do?<br />
</li>
<li>
How do you convert a string containing a number, e.g. "42", into an integer number?<br />
</li>
<li>
Strings are immutable, what does that mean?<br />
</li>
<li>
If you want to compare strings and numbers you have to be a little careful. What is the difference between the "==" and the "===" operators?<br />
</li>
<li>
The class String has many methods. We used the following:<br />
substring()<br />
length()<br />
charAt()<br />
toLowerCase()<br />
indexOf()<br />
Briefly describe what each of these methods does.<br />
</li>
<li>
Write example code that reverses a string, e.g. converts the word "STRESSED" into the word "DESSERT". (The pure JavaScript code is sufficient, a class or method declaration is not needed).<br />
</li>
<li>
What is the StringTokenizer class used for?<br />
</li>
<li>
The class StringTokenizer takes a string as parameter and has two methods called hasMoreTokens() and nextToken(). Write code that asks the user for a sentence, and then outputs the individual words of the sentence, line by line.</li>
</ol>
<p>
.</p>
<hr />
<h1>
References</h1>
<p>
The references from Chapter 2 are still important here. The Wikipedia also contains a lot of information.</p>
<p>
[1] Caesar cipher, <a href="https://en.wikipedia.org/w/index.php?title=Caesar_cipher&oldid=702242426">https://en.wikipedia.org/w/index.php?title=Caesar_cipher&oldid=702242426</a> (last visited Feb. 17, 2016).</p>
<p>
[2] Abjad, <a href="https://en.wikipedia.org/w/index.php?title=Abjad&oldid=704692935">https://en.wikipedia.org/w/index.php?title=Abjad&oldid=704692935</a> (last visited Feb. 17, 2016).</p>
<p>
[3] Pidgin-Sprachen, <a href="https://de.wikipedia.org/w/index.php?title=Pidgin-Sprachen&oldid=147087583">https://de.wikipedia.org/w/index.php?title=Pidgin-Sprachen&oldid=147087583</a> (last visited Feb. 17, 2016).</p>
<p>
[4] String (Java Platform SE 7 ) - Oracle Documentation, <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html">https://docs.oracle.com/javase/7/docs/api/java/lang/String.html</a></p>
<p>
[5] Pig Latin, <a href="https://de.wikipedia.org/w/index.php?title=Pig_Latin&oldid=149209295">https://de.wikipedia.org/w/index.php?title=Pig_Latin&oldid=149209295</a> (Abgerufen: 17. Februar 2016, 20:54 UTC).</p>
<p>
[6] Sprachtypologie, <a href="https://de.wikipedia.org/w/index.php?title=Sprachtypologie&oldid=149705787">https://de.wikipedia.org/w/index.php?title=Sprachtypologie&oldid=149705787</a> (Abgerufen: 17. Februar 2016, 21:10 UTC).</p>
<p>
[7] ELIZA, <a href="https://en.wikipedia.org/w/index.php?title=ELIZA&oldid=704986757">https://en.wikipedia.org/w/index.php?title=ELIZA&oldid=704986757</a> (last visited Feb. 17, 2016).</p>
<p>
[8] Telemarketing-Software Samantha, <a href="http://de.engadget.com/2013/12/11/audio-telemarketing-software-samatha-streitet-kategorisch-ab-e/">http://de.engadget.com/2013/12/11/audio-telemarketing-software-samatha-streitet-kategorisch-ab-e/</a></p>
<p>
[9] Blackjack, <a href="https://en.wikipedia.org/wiki/Blackjack">https://en.wikipedia.org/wiki/Blackjack</a></p>
<p>
[10] Craps, <a href="https://de.wikipedia.org/wiki/Craps">https://de.wikipedia.org/wiki/Craps</a></p>
<p>
[11] Fibonacci-Folge, <a href="https://de.wikipedia.org/wiki/Fibonacci-Folge">https://de.wikipedia.org/wiki/Fibonacci-Folge</a></p>
<p>
[12] Galgenmännchen, <a href="https://de.wikipedia.org/wiki/Galgenmännchen">https://de.wikipedia.org/wiki/Galgenmännchen</a></p>
<p>
[13] Mind Reader: a program that predicts choices, <a href="http://nifty.stanford.edu/2007/raja-mindreader/">http://nifty.stanford.edu/2007/raja-mindreader/</a></p>
<p>
.</p>
<p class="footer">
Copyright © 2016-2023 <a href="http://www.lano.de">Ralph P. Lano</a>. All rights reserved.
</p>
</div>
</div>
</center>
</body>
</html>