Skip to content

Commit bcae59e

Browse files
Use templates to generate concept exercise introductions (exercism#2364)
1 parent 1a6839e commit bcae59e

30 files changed

Lines changed: 152 additions & 38 deletions

File tree

concepts/chars/introduction.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ The Java `char` type represents the smallest addressable components of text.
44
Multiple `char`s can comprise a string such as `"word"` or `char`s can be
55
processed independently. Their literals have single quotes e.g. `'A'`.
66

7-
Java `char`s support Unicode encoding, so in addition to the Latin character set
8-
most modern writing systems can be represented,
9-
e.g. Greek `'β'`.
7+
Java `char`s support Unicode encoding so in addition to the Latin character set
8+
pretty much all the writing systems in use worldwide can be represented,
9+
e.g. the Greek letter `'β'`.
1010

1111
There are many builtin library methods to inspect and manipulate `char`s. These
1212
can be found as static methods of the `java.lang.Character` class.
1313

1414
`char`s are sometimes used in conjunction with a `StringBuilder` object.
1515
This object has methods that allow a string to be constructed
1616
character by character and manipulated. At the end of the process
17-
`toString()` can be called on it to output a complete string.
18-
19-
In order to get chars from the String one could use `String.charAt(index)` method.
17+
`toString` can be called on it to output a complete string.

concepts/interfaces/introduction.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public interface Language {
1010
String speak();
1111
}
1212

13-
public class ItalianTaveller implements Language, Cloneable {
13+
public class ItalianTraveller implements Language, Cloneable {
1414

1515
// from Language interface
1616
public String getLanguageName() {
17-
return "Italiano";
17+
return "Italiano";
1818
}
1919

2020
// from Language interface
@@ -23,8 +23,8 @@ public class ItalianTaveller implements Language, Cloneable {
2323
}
2424

2525
// from Cloneable interface
26-
public Object Clone() {
27-
ItalianTaveller it = new ItalianTaveller();
26+
public Object clone() {
27+
ItalianTraveller it = new ItalianTraveller();
2828
return it;
2929
}
3030
}

concepts/switch-statement/introduction.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Like an _if/else_ statement, a `switch` statement allows you to change the flow
44

55
Some keywords are useful when using a switch statement.
66

7-
- `switch` : this keyword allows you to declare the structure of the switch. It is followed by the expression or the variable that will make the result change.
8-
- `case` : you will use this to declare the differents possibilties for the result.
7+
- `switch` : this keyword allows you to declare the structure of the switch. It is followed by the expression or the variable that will change the result.
8+
- `case` : you will use this keyword to declare the different possibilities for the result.
99
- `break` : the `break` keyword is very useful in order to stop the execution of the switch at the end of the wanted flow. If you forget it, the program will continue and may lead to unexpected results.
10-
- `default` : as its name says, use it as a default result when no other case matchs your expression's result.
10+
- `default` : as its name says, use it as a default result when no other case matches your expression's result.
1111

12-
At their simplest, they test a primitive or string expression and make a decision based on its value. For example:
12+
At their simplest they test a primitive or string expression and make a decision based on its value. For example:
1313

1414
```java
1515
String direction = getDirection();
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Introduction
22

3+
## Booleans
4+
35
Booleans in Java are represented by the `boolean` type, which values can be either `true` or `false`.
46

5-
Java supports three boolean operators: `!` (NOT), `&&` (AND), and `||` (OR).
7+
Java supports three boolean operators:
8+
9+
- `!` (NOT): negates the boolean
10+
- `&&` (AND): takes two booleans and results in true if they're both true
11+
- `||` (OR): results in true if any of the two booleans is true
12+
13+
**Examples**
14+
15+
```java
16+
!true // => false
17+
!false // => true
18+
true && false // => false
19+
true && true // => true
20+
false || false // => false
21+
false || true // => true
22+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Introduction
2+
3+
%{concept:booleans}

exercises/concept/bird-watcher/.docs/introduction.md

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,67 @@
1-
# Arrays
1+
# Introduction
22

3-
In Java, data structures that can hold zero or more elements are known as _collections_. An **array** is a collection that has a fixed size/length and whose elements must all be of the same type. Elements can be assigned to an array or retrieved from it using an index. Java arrays are zero-based, meaning that the first element's index is always zero:
3+
## Arrays
4+
5+
In Java, data structures that can hold zero or more elements are known as _collections_.
6+
An **array** is a collection that has a fixed size and whose elements must all be of the same type.
7+
Elements can be assigned to an array or retrieved from it using an index.
8+
Java arrays use zero-based indexing: the first element's index is 0, the second element's index is 1, etc.
9+
10+
Here is the standard syntax for initializing an array:
11+
12+
```java
13+
type[] variableName = new type[size];
14+
```
15+
16+
The `type` is the type of elements in the array which may be a primitive type (e.g. `int`) or a class (e.g. `String`).
17+
18+
The `size` is the number of elements this array will hold (which cannot be changed later).
19+
After array creation, the elements are initialized to their default values (typically `0`, `false` or `null`).
420

521
```java
622
// Declare array with explicit size (size is 2)
723
int[] twoInts = new int[2];
24+
```
25+
26+
Arrays can also be defined using a shortcut notation that allows you to both create the array and set its value:
827

28+
```java
29+
// Two equivalent ways to declare and initialize an array (size is 3)
30+
int[] threeIntsV1 = new int[] { 4, 9, 7 };
31+
int[] threeIntsV2 = { 4, 9, 7 };
32+
```
33+
34+
As the compiler can now tell how many elements the array will have, the length can be omitted.
35+
36+
Array elements may be assigned and accessed using a bracketed index notation:
37+
38+
```java
939
// Assign second element by index
1040
twoInts[1] = 8;
1141

1242
// Retrieve the second element by index and assign to the int element
13-
int element = twoInts[1];
43+
int secondElement = twoInts[1];
1444
```
1545

16-
Arrays can also be defined using a shortcut notation that allows you to both create the array and set its value. As the compiler can now tell how many elements the array will have, the length can be omitted:
46+
Accessing an index that is outside of the valid indexes for the array results in an `IndexOutOfBoundsException`.
47+
48+
Arrays can be manipulated by either calling an array instance's methods or properties, or by using the static methods defined in the `Arrays` class (typically only used in generic code).
49+
The most commonly used property for arrays is its length which can be accessed like this:
1750

1851
```java
19-
// Two equivalent ways to declare and initialize an array (size is 3)
20-
int[] threeIntsV1 = new int[] { 4, 9, 7 };
21-
int[] threeIntsV2 = { 4, 9, 7 };
52+
int arrayLength = someArray.length;
2253
```
2354

24-
Arrays can be manipulated by either calling an array instance's methods or properties, or by using the static methods defined in the `Arrays` class.
55+
Java also provides a helpful utility class [`java.util.Arrays`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Arrays.html) that has lots of useful array-related methods (eg. `Arrays.equals`).
56+
57+
Java also supports [multi-dimensional arrays](https://www.programiz.com/java-programming/multidimensional-array) like `int[][] arr = new int[3][4];` which can be very useful.
2558

26-
The fact that an array is also a _collection_ means that, besides accessing values by index, you can iterate over _all_ its values using a `foreach` loop:
59+
The fact that an array is also a _collection_ means that, besides accessing values by index, you can iterate over _all_ its values using a `for-each` loop:
2760

2861
```java
2962
char[] vowels = { 'a', 'e', 'i', 'o', 'u' };
3063

31-
for(char vowel:vowels) {
64+
for(char vowel: vowels) {
3265
// Output the vowel
3366
System.out.print(vowel);
3467
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Introduction
2+
3+
%{concept:arrays}

exercises/concept/blackjack/.docs/introduction.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Introduction
22

3-
## Logical Operators
3+
## Conditionals If
4+
5+
### Logical Operators
46

57
Java supports the three logical operators `&&` (AND), `||` (OR), and `!` (NOT).
68

7-
## If statement
9+
### If statement
810

911
The underlying type of any conditional operation is the `boolean` type, which can have the value of `true` or `false`. Conditionals are often used as flow control mechanisms to check for various conditions. For checking a particular case an `if` statement can be used, which executes its code if the underlying condition is `true` like this:
1012

@@ -28,7 +30,7 @@ if(val == 10) {
2830
}
2931
```
3032

31-
## Switch statement
33+
### Switch statement
3234

3335
Java also provides a `switch` statement for scenarios with multiple options.
3436

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Introduction
2+
3+
%{concept:conditionals-if}

exercises/concept/cars-assemble/.docs/introduction.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Introduction
22

3+
## Numbers
4+
35
There are two different types of numbers in Java:
46

57
- Integers: numbers with no digits behind the decimal separator (whole numbers). Examples are `-6`, `0`, `1`, `25`, `976` and `-500000`.
68
- Floating-point numbers: numbers with zero or more digits behind the decimal separator. Examples are `-20.4`, `0.1`, `2.72`, `16.984025` and `1024.0`.
79

810
The two most common numeric types in Java are `int` and `double`. An `int` is a 32-bit integer and a `double` is a 64-bit floating-point number.
911

10-
Arithmetic is done using the standard arithmetic operators. Numbers can be compared using the standard numeric comparison operators and the equality (`==`) and inequality (`!=`) operators.
12+
Arithmetic is done using the standard arithmetic operators. Numbers can be compared using the standard numeric comparison operators (eg. `5 > 4` and `4 <= 5`) and the equality (`==`) and inequality (`!=`) operators.
1113

1214
Java has two types of numeric conversions:
1315

@@ -30,4 +32,4 @@ if (x == 5) {
3032
}
3133
```
3234

33-
The condition of an `if` statement must be of type `boolean`. Java has no concept of _truthy_ values.
35+
The condition of an `if` statement must be of type `boolean`.

0 commit comments

Comments
 (0)