You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: data/part-1/1-starting-programming.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ Modern programming is practically always done in an IDE (integrated development
24
24
25
25
<!-- Käytämme tällä kurssilla [NetBeans](https://netbeans.apache.org)-nimistä ohjelmointiympäristöä sekä siihen liitettävää Test My Code -liitännäistä. -->
26
26
27
-
The IDE we use on this course is called [NetBeans](https://netbeans.apache.org), and we use it with Test My Code plugin.
27
+
The IDE we use on this course is called [NetBeans](https://netbeans.apache.org), and we use it with the Test My Code plugin.
28
28
29
29
<!-- Tarvitset kurssin aloittamiseen (1) käyttäjätunnuksen kurssilla käytettyyn TMC-järjestelmään, (2) Javan (Java JDK), ja (3) NetBeans with TMC -ohjelmointiympäristön (jatkossa TMC). Näiden asentaminen onnistuu seuraavia ohjeita noudattamalla. -->
Copy file name to clipboardExpand all lines: data/part-1/3-reading-input.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -361,7 +361,7 @@ Once upon a time...
361
361
## Input String as a Part of Output
362
362
363
363
<!-- Huomasimme ohjelmointitehtävässä "Hei Ada Lovelace!", että merkkijonoliteraaleja ja merkkijonomuuttujia voidaan yhdistää `+`-merkillä. Alla oleva esimerkki näyttää ohjelman, missä käyttäjältä luetaan merkkijono, joka tulostetaan merkkijonoliteraaliin yhdistettynä. -->
364
-
We noticed in the "Hi Ava Lovelace!" exercise that string literals and string variables can be joined using the `+`-operator. The example below demonstrates a program that takes user input and prints it concatenated with a string literal.
364
+
We noticed in the "Hi Ada Lovelace!" exercise that string literals and string variables can be joined using the `+` operator. The example below demonstrates a program that takes user input and prints it concatenated with a string literal.
365
365
366
366
```java
367
367
importjava.util.Scanner;
@@ -575,7 +575,7 @@ public class Program {
575
575
576
576
System.out.println("Last string you wrote was "+ third +", which ");
577
577
System.out.println("was preceded by "+ second+".");
578
-
System.out.println("The first string was"+ first +".");
578
+
System.out.println("The first string was"+ first +".");
579
579
580
580
System.out.println("All together: "+ first + second + third);
Copy file name to clipboardExpand all lines: data/part-1/4-variables.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,7 @@ Open the questionnaire by following the link
49
49
50
50
<!-- Tutustuimme syötteen lukemisen yhteydessä jo pikaisesti merkkijonomuuttujiin. Tutustutaan seuraavaksi muihin usein käytettyihin Javan muuttujatyyppeihin. -->
51
51
52
-
We've already familiarized ourselvese with strings to a degree while dealing with user inputs. Let's turn our attention to learning about other variable *types* commonly used in Java.
52
+
We've already familiarized ourselves with strings to a degree while dealing with user inputs. Let's turn our attention to learning about other variable *types* commonly used in Java.
53
53
54
54
<!-- Muuttujaa kannattaa ajatella lokerona, johon voi tallettaa annetun tyyppistä tietoa. Tyyppejä ovat esimerkiksi teksti eli merkkijono (`String`), kokonaisluku (`int`), liukuluku (`double`) eli desimaaliluku, ja totuusarvo (`boolean`). Muuttujaan asetetaan arvo yhtäsuuruusmerkillä (`=`). -->
Copy file name to clipboardExpand all lines: data/part-1/6-conditional-statements.md
+15-13Lines changed: 15 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -476,8 +476,10 @@ Greater number is: 8
476
476
477
477
<sample-output>
478
478
479
-
Give the first number; **5**
480
-
Give the second number: **5**
479
+
Give the first number:
480
+
**5**
481
+
Give the second number:
482
+
**5**
481
483
The numbers are equal!
482
484
483
485
</sample-output>
@@ -1167,13 +1169,13 @@ int number = 7;
1167
1169
if (!(number >4)) {
1168
1170
System.out.println("The number is not greater than 4.");
1169
1171
} else {
1170
-
System.out.println("The number is greater than or equal to 4.")
1172
+
System.out.println("The number is greater than 4.")
1171
1173
}
1172
1174
```
1173
1175
1174
1176
<sample-output>
1175
1177
1176
-
The number is greater than or equal to 4.
1178
+
The number is greater than 4.
1177
1179
1178
1180
</sample-output>
1179
1181
@@ -1524,17 +1526,17 @@ if (number % 4 != 0) {
1524
1526
1525
1527
When a gift is given by a close relative or a family member, the amount of gift tax is determined by the following table (source [vero.fi](https://www.vero.fi/en/individuals/property/gifts/gift-tax-calculator/#gifttaxtables)):
1526
1528
1527
-
| Value of gift | Tax at the lower limit | Tax rate(%) for exceeding part |
<!-- Esimerkiksi 6000 euron lahjasta tulee maksaa veroa 180 euroa (100 + (6000-5000) * 0.08), ja 75000 euron lahjasta tulee maksaa veroa 7100 euroa (4700 + (75000-55000) * 0.12). -->
1536
-
1537
-
For example 6000€ gift implies 180€ of gift tax (100 + (6000-5000)_0.08), and 75000€ gift implies 7100€ of gift tax (4700 + (75000-55000) _ 0.12).
1538
+
<!-- The formula used to calculate the gift tax is: (Tax at the lower limit + (Value of gift (€) - minimum value of gift (€)) * (Tax Rate (%) / 100) -->
1539
+
For example 6000€ gift implies 180€ of gift tax (100 + (6000-5000) * 0.08), and 75000€ gift implies 7100€ of gift tax (4700 + (75000-55000) * 0.12).
1538
1540
1539
1541
<!-- Tee ohjelma, joka laskee lahjaveron lähimmiltä sukulaisilta annetulle lahjalle. Alla on muutama esimerkki ohjelman toiminnasta. -->
Copy file name to clipboardExpand all lines: data/part-10/1-handling-collections-as-streams.md
+16-16Lines changed: 16 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -143,7 +143,7 @@ double average = inputs.stream()
143
143
<!-- Keskiarvon laskeminen onnistuu virrasta, jolle on kutsuttu `mapToInt`-metodia. Kokonaislukuja sisältävällä virralla on metodi `average()`, joka palauttaa <a href="https://docs.oracle.com/javase/8/docs/api/java/util/OptionalDouble.html" target="_blank" norel>OptionalDouble</a>-tyyppisen olion. Oliolla on metodi `getAsDouble()`, joka palauttaa listan arvojen keskiarvon `double`-tyyppisenä muuttujana.
144
144
145
145
Lyhyt yhteenveto tähän mennessä tutuiksi tulleista virtaan liittyvistä metodeista. -->
146
-
Calculating the average is possible from a stream that has the `mapToInt` method called on it. A stream of integers has an `average` method that returns an <ahref="https://docs.oracle.com/javase/8/docs/api/java/util/OptionalDouble.html"target="_blank"norel>OptionalDouble</a>-type object. The object has `getAsDouble()` method that returns the average of the list values as a type `double`varaible.
146
+
Calculating the average is possible from a stream that has the `mapToInt` method called on it. A stream of integers has an `average` method that returns an <ahref="https://docs.oracle.com/javase/8/docs/api/java/util/OptionalDouble.html"target="_blank"norel>OptionalDouble</a>-type object. The object has `getAsDouble()` method that returns the average of the list values as a `double`type variable.
147
147
148
148
A brief summary of the stream methods we've encountered so far.
149
149
@@ -216,7 +216,7 @@ A brief summary of the stream methods we've encountered so far.
216
216
217
217
<tr>
218
218
<td>
219
-
Stream formation: `stream()`
219
+
Stream formation: <code>stream()</code>
220
220
</td>
221
221
<td>
222
222
The method is called on collection that implements the Collection interface, such as an ArrayList Object. Something is done on the created stream.
@@ -225,7 +225,7 @@ A brief summary of the stream methods we've encountered so far.
225
225
226
226
<tr>
227
227
<td>
228
-
Converting a stream into an integer stream: `mapToInt(value -> another)`
228
+
Converting a stream into an integer stream: <code>mapToInt(value -> another)</code>
229
229
</td>
230
230
<td>
231
231
The stream transforms into one containing integers.
@@ -237,30 +237,30 @@ A brief summary of the stream methods we've encountered so far.
237
237
<tr>
238
238
<td>
239
239
Filtering values:
240
-
`filter(value -> filter condition)`
240
+
<code>filter(value -> filter condition)</code>
241
241
</td>
242
242
<td>
243
243
The elements that do not satisfy the filter condition are removed from the string.
244
244
On the right side of the arrow is a statement that returns a boolean.
245
-
If the boolean is `true`, the element is accepted into the stream. If the boolean evaluates to false, the value is not accepted into the stream. Something is done with the filtered values.
245
+
If the boolean is <code>true</code>, the element is accepted into the stream. If the boolean evaluates to false, the value is not accepted into the stream. Something is done with the filtered values.
246
246
</td>
247
247
</tr>
248
248
249
249
<tr>
250
250
<td>
251
-
Calculating the average: `average()`
251
+
Calculating the average: <code>average()</code>
252
252
</td>
253
253
<td>
254
-
Returns a OptionalDouble-type object that has a method `getAsDouble()` that returns a value of type `double`. Calling the method `average()` works on streams that contain integers - they can be created with the `mapToInt` method.
254
+
Returns a OptionalDouble-type object that has a method <code>getAsDouble()</code> that returns a value of type <code>double</code>. Calling the method <code>average()</code> works on streams that contain integers - they can be created with the <code>mapToInt</code> method.
255
255
</td>
256
256
</tr>
257
257
258
258
<tr>
259
259
<td>
260
-
Counting the number of elements in a stream: `count()`
260
+
Counting the number of elements in a stream: <code>count()</code>
261
261
</td>
262
262
<td>
263
-
Returns the number of elements in a stream as a `long`-type value.
263
+
Returns the number of elements in a stream as a <code>long</code>-type value.
264
264
</td>
265
265
</tr>
266
266
@@ -353,7 +353,7 @@ Average of the positive numbers: 1.5
353
353
Miksi funktiot kirjoitetaan muodossa `luku -> luku > 5`?
354
354
355
355
Kyseinen kirjoitusmuoto, *lambda-lauseke*, on Javan tarjoama lyhenne ns. anonyymeille metodeille, joilla ei ole "omistajaa" eli ne eivät ole osa luokkaa tai rajapintaa. Funktio sisältää sekä parametrien määrittelyn että funktion rungon. Saman funktion voi kirjoittaa useammalla eri tavalla, kts. alla. -->
356
-
Stream values are handled by methods related to streams. Methods that handle values get a function as a parameter that determines what is done with each element. What the function does is specific to the method in question. For instance, the `filter` method used for filtering elements is provided a function which returns the a boolean `true` or `false`, depending on whether to keep the value in the stream or not. The `mapToInt` method used for transformation is, on the other hand, provided a function which converts the value to an integer, and so on.
356
+
Stream values are handled by methods related to streams. Methods that handle values get a function as a parameter that determines what is done with each element. What the function does is specific to the method in question. For instance, the `filter` method used for filtering elements is provided a function which returns a boolean `true` or `false`, depending on whether to keep the value in the stream or not. The `mapToInt` method used for transformation is, on the other hand, provided a function which converts the value to an integer, and so on.
357
357
358
358
Why are the functions written in the form `value -> value > 5`?
359
359
@@ -438,7 +438,7 @@ The function can also be passed directly as a parameter. The syntax found below
438
438
<!-- Virran arvoja käsittelevät funktiot eivät voi muuttaa funktion ulkopuolisten muuttujien arvoja. Kyse on käytännössä staattisten metodien käyttäytymisestä -- metodia kutsuttaessa metodin ulkopuolisiin muuttujiin ei pääse käsiksi. Funktioiden tilanteessa funktion ulkopuolisten muuttujien arvoja voi lukea olettaen, että luettavien muuttujien arvot eivät muutu lainkaan ohjelmassa.
439
439
440
440
Alla oleva ohjelma demonstroi tilannetta, missä funktiossa yritetään hyödyntää funktion ulkopuolista muuttujaa. Tämä ei toimi. -->
441
-
Functions thats handle stream elements cannot change values of variables outside of the function. This has to do with how static methods behave - during a method call, there is no access to any variables outside of the method. With functions, the values of variables outside the function can be read, assuming that those values of those variables do not change in the program.
441
+
Functions that handle stream elements cannot change values of variables outside of the function. This has to do with how static methods behave - during a method call, there is no access to any variables outside of the method. With functions, the values of variables outside the function can be read, assuming that those values of those variables do not change in the program.
442
442
443
443
The program below demonstrates the situation in which a function attempts to make use of a variable outside the function. It doesn't work.
444
444
@@ -564,7 +564,7 @@ Implement the method using stream! For collecting the numbers try the command `C
564
564
565
565
Metodi `count` kertoo virran alkioiden lukumäärän `long`-tyyppisenä muuttujana. -->
566
566
567
-
Let's take a look at four terminal operations: the `count` method for counting the number of values on a list using the, the `forEach` method for going a through list values, the `collect` method for gathering the list values into a data structure, and the `reduce` method for combining the list items.
567
+
Let's take a look at four terminal operations: the `count` method for counting the number of values on a list, the `forEach` method for going a through list values, the `collect` method for gathering the list values into a data structure, and the `reduce` method for combining the list items.
568
568
569
569
The `count` method informs us of the number of values in the stream as a `long`-type variable.
570
570
@@ -601,7 +601,7 @@ Values: 5
601
601
</sample-output>
602
602
603
603
<!-- Metodi `forEach` kertoo mitä kullekin listan arvolle tulee tehdä ja samalla päättää virran käsittelyn. Alla olevassa esimerkissä luodaan ensin numeroita sisältävä lista, jonka jälkeen tulostetaan vain kahdella jaolliset luvut. -->
604
-
The `forEach` method defines what is done to each list value and terminated the stream processing. In the example below, we first create a list of numbers, after which we only print the numbers that are divisible by two.
604
+
The `forEach` method defines what is done to each list value and terminates the stream processing. In the example below, we first create a list of numbers, after which we only print the numbers that are divisible by two.
@@ -1288,7 +1288,7 @@ The exercise template includes the probably familiar project "Cargo hold". Howev
1288
1288
<!--Virta on myös erittäin näppärä tiedostojen käsittelyssä.Tiedoston lukeminen virtamuotoisena tapahtuu Javan valmiin <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html" target="_blank" rel="noopener">Files</a>-luokan avulla. Files-luokan metodin `lines` avulla tiedostosta voidaan luoda syötevirta, jonka avulla tiedoston rivit voidaan käsitellä yksi kerrallaan. Metodi `lines` saa patametrikseen polun, joka luodaan luokan <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Paths.html" target="_blank" rel="noopener">Paths</a> tarjoamalla metodilla `get`, jolle annetaan parametrina tiedostopolkua kuvaava merkkijono.
1289
1289
1290
1290
Alla olevassa esimerkissä luetaan tiedoston "tiedosto.txt" kaikki rivit ja lisätään ne listaan. -->
1291
-
<p>Streams are also very handy in handling files. The file is read in stream form using Java's ready-made <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html" target="_blank" rel="noopener">Files</a> class. The `lines` method in the files class allows you to create an input stream from a file, allowing you to process the rows one by one. The `lines` method gets a path as its parameter, which is created using the `get` method in the <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Paths.html" target="_blank" rel="noopener">Paths</a> class. The `get` method is provided a string describing the file path.</p>
1291
+
<p>Streams are also very handy in handling files. The file is read in stream form using Java's ready-made <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html" target="_blank" rel="noopener">Files</a> class. The <code>lines</code> method in the files class allows you to create an input stream from a file, allowing you to process the rows one by one. The <code>lines</code> method gets a path as its parameter, which is created using the <code>get</code> method in the <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Paths.html" target="_blank" rel="noopener">Paths</a> class. The <code>get</code> method is provided a string describing the file path.</p>
1292
1292
1293
1293
The example below reads all the lines in "file.txt" and adds them to the list.
0 commit comments