Skip to content

Commit 6922baa

Browse files
bowbahdoefirasrg
andauthored
Merge more runnable code-adjacent features (#29)
* more sections * First feedback round * Update prelude.md * ... * Spelling fix Co-Authored-By: Firas Regaieg <[email protected]> * Arguments chapter * More Challenges * Run prettier * user input * October 14th, #1 * Array challenges * Delete challenges * Null * ... * Update null_as_absence.md * Delete out.json * Fix quotes * Add first no_runs * Fix number example --------- Co-authored-by: Firas Regaieg <[email protected]>
1 parent 23fc7a5 commit 6922baa

35 files changed

+257
-165
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Book teaching how to write modern and effective Java. It is maintained by the community, anyone can contribute.
88

9-
Feel free to join our [discord server](https://discord.com/invite/XXFUXzK)
9+
Feel free to join our [discord server](https://discord.gg/together-java-272761734820003841)
1010
if you have any questions, or require assistance with the project. :relaxed:
1111

1212
## Getting started

book.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ additional-css = ["ferris.css"]
1313
additional-js = ["ferris.js"]
1414

1515
[output.html.fold]
16-
enable = true # whether or not to enable section folding
17-
level = 0 # the depth to start folding
16+
enable = true # whether or not to enable section folding
17+
level = 0 # the depth to start folding
1818

1919
[preprocessor.features]
2020
command = "python3 features.py"
@@ -29,3 +29,5 @@ java_21 = false
2929
[output.html.playground]
3030
editable = true
3131

32+
[output.html.code.hidelines]
33+
java = "~"

features.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ def preprocess_section(context, section):
4949

5050
json_input = json.load(sys.stdin)
5151
context, book = json_input
52-
53-
with open("out.json", "w") as f:
54-
json.dump(json_input, f)
5552

5653
for section in book["sections"]:
5754
preprocess_section(context, section)

ferris.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var ferrisTypes = [
55
},
66
{
77
attr: 'panics',
8-
title: 'This code panics!'
8+
title: 'This code will crash!'
99
},
1010
{
1111
attr: 'not_desired_behavior',

out.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/SUMMARY.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,17 @@
9595
# Control Flow I
9696

9797
- [Branching Paths](./branching_paths.md)
98+
9899
- [If](./branching_logic/if.md)
99-
- [Else](./branching_logic/else.md)
100100
- [Nested Ifs](./branching_logic/nested_ifs.md)
101+
- [Else](./branching_logic/else.md)
101102
- [Else If](./branching_logic/else_if.md)
102103
- [Relation to Delayed Assignment](./branching_logic/relation_to_delayed_assignment.md)
104+
- [Scoped Variables](./branching_logic/scoped_variables.md)
103105
- [Conditional Operator](./branching_logic/conditional_operator.md)
104106
- [Boolean Expressions](./branching_logic/boolean_expressions.md)
105107
- [Challenges](./branching_logic/challenges.md)
108+
106109
- [Loops](./loops.md)
107110
- [While](./loops/while.md)
108111
- [Endless Loops](./loops/endless_loops.md)
@@ -164,11 +167,10 @@
164167
- [Declaration](./methods/declaration.md)
165168
- [Invocation](./methods/invocation.md)
166169
- [Scope](./methods/scope.md)
167-
- [Return](./methods/return.md)
168-
- [Unreachable Statements](./methods/unreachable_statements.md)
169170
- [main](./methods/main.md)
170171
- [Challenges](./methods/challenges.md)
171172
- [Arguments](./arguments.md)
173+
172174
- [Declaration](./arguments/declaration.md)
173175
- [Invocation with Arguments](./arguments/invocation_with_arguments.md)
174176
- [Reassignment](./arguments/reassignment.md)
@@ -177,22 +179,22 @@
177179
- [Overloading](./arguments/overloading.md)
178180
- [Inferred Types](./arguments/inferred_types.md)
179181
- [Challenges](./arguments/challenges.md)
180-
- [Return Values](./return_values.md)
181-
- [void](./return_values/void.md)
182+
183+
- [Return](./return_values.md)
184+
- [Return Values](./return_values/return_values.md)
182185
- [Conversion](./return_values/conversion.md)
186+
- [void](./return_values/void.md)
187+
- [Unreachable Statements](./return_values/unreachable_statements.md)
183188
- [Pure Functions](./return_values/pure_functions.md)
184189
- [Impure Functions](./return_values/impure_functions.md)
185190

186-
# User Input
187-
188-
- [User Input](./user_input.md)
189-
190191
# Data Types III
191192

192193
- [Identity Types](./identity_types.md)
193194
- [Comparison with ==](./identity_types/comparison_with_equalsequals.md)
194195
- [Primitive Types](./primitive_types.md)
195196
- [null](./null.md)
197+
- [Null as Absence](./null/null_as_absence.md)
196198
- [Checking for null](./null/checking_for_null.md)
197199
- [Field Access](./null/field_access.md)
198200
- [Instance Methods](./null/instance_methods.md)
@@ -205,7 +207,7 @@
205207
- [Unboxing Conversion](./boxed_primitives/unboxing_conversion.md)
206208
- [Boxing Conversion](./boxed_primitives/boxing_conversion.md)
207209
- [Arrays of Boxed Primitives](./boxed_primitives/arrays_of_boxed_primitives.md)
208-
- [Challenges](./arguments/challenges.md)
210+
- [Challenges](./boxed_primitives/challenges.md)
209211
- [Arrays II](./arrays_ii.md)
210212
- [Default Values](./arrays_ii/default_values.md)
211213
- [Populate Array]()

src/arguments/final_arguments.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,4 @@ This has the same use as regular final variables. If there are lots of lines
3232
of code where a variable might be reassigned, it can be useful to not have
3333
to read all that code to know that it does happen.[^opinion]
3434

35-
[^opinion]:
36-
Adding `final` to all arguments can make it harder to read the code, simply
37-
because of visual noise.
35+
[^opinion]: Adding `final` to all arguments can make it harder to read the code, simply because of visual noise.

src/arguments/overloading.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,4 @@ void main() {
3434
When there are multiple methods that have the same name but take different arguments,
3535
those methods are considered "overloads" of eachother[^overload]
3636

37-
[^overload]:
38-
"Overloading" in this context means when one word has more than
39-
one possible meaning depending on how it is used. Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo.
37+
[^overload]: "Overloading" in this context means when one word has more than one possible meaning depending on how it is used. Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo.

src/arrays/array_initializers.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,4 @@ int[] numbers = { 1, two, two + 1 }
2121

2222
We call them array initializers because you use them to give an initial value to an array.[^pattern]
2323

24-
[^pattern]:
25-
You may be noticing a pattern. Confusing sounding names are often kinda "obvious"
26-
with enough context.
24+
[^pattern]: You may be noticing a pattern. Confusing sounding names are often kinda "obvious" with enough context.

src/arrays/challenges.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,78 @@ Remember the rules for this are
66
- Try not to give up until you've given it a solid attempt
77

88
## Challenge 1
9+
10+
Edit the following program so that the output is zero.
11+
12+
```java
13+
void main() {
14+
// Only change this line
15+
String[] words = { "Sam", "I", "Am" };
16+
System.out.println(array.length);
17+
}
18+
```
19+
20+
## Challenge 2
21+
22+
Using only `System.out.println` and array accesses,
23+
print `hello world` to the screen.
24+
25+
```java
26+
void main() {
27+
char[] letters = {
28+
' ',
29+
'h',
30+
'e',
31+
'l',
32+
'o',
33+
'w',
34+
'r',
35+
'd'
36+
};
37+
38+
// Your code here
39+
}
40+
```
41+
42+
## Challenge 3
43+
44+
Without editing either the array declaration or the loop at the bottom,
45+
make the output of this program `0`.
46+
47+
```java
48+
void main() {
49+
final int numbers = { 1, 2, 3, 4 };
50+
51+
// -----------
52+
// YOUR CODE HERE
53+
54+
55+
// -----------
56+
int total = 0;
57+
int index = 0;
58+
while (index < numbers.length) {
59+
total += numbers[index];
60+
index += 1;
61+
}
62+
System.out.println(total);
63+
}
64+
```
65+
66+
## Challenge 4
67+
68+
Make this program output `bulbasaur` without changing anything
69+
above or below the marked areas.
70+
71+
```java
72+
void main() {
73+
char[] name = { 'b', 'u', 'l', 'b' };
74+
75+
// -----------
76+
// YOUR CODE HERE
77+
78+
79+
// -----------
80+
char[] toPrint = name;
81+
System.out.println(toPrint);
82+
}
83+
```

0 commit comments

Comments
 (0)