Skip to content
This repository was archived by the owner on Nov 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is loosely inspired by Keep a Changelog.

### Changed

- **Web 0.14.27, VisuBot: `forward`/`backward` overloaded with a unit:** besides `mbot.forward()` (10 cm) and `mbot.forward(30)` there is now `mbot.forward(2, "Umdrehungen")` and `mbot.forward(30, "cm")` (en `"rotations"`, pt `"rotações"`), same for `backward`. One wheel rotation is π · 6.5 cm ≈ 20.4 cm; the action stores the distance in cm, so simulation, exercise check and the real robot (`mbot2.straight`) work unchanged, and the console shows e.g. „2 Umdrehungen vorwärts (40.84 cm)“. An unknown unit is an error naming the allowed units. The CyberPi program export gets the same overload. VisuBot lesson 22 gets a step „Gleicher Name, andere Parameter: Überladung“ with the three headers, a Ludwig Angeberwissen asking pupils to measure their own robot with a printable test record (PDF, de/en, `website/visubot/messprotokoll-radumdrehung.pdf` / `test-record-wheel-rotation.pdf`: wheel diameter, five test cases expected vs. actual, evaluation, causes, feedback for the teacher, box „So testet man Softwaresysteme“), the exercise „Quadrat mit Umdrehungen“ and a quiz; Nachschlagen, glossary („Überladung“) and code completion list the new variants (de/en).
- **Web 0.14.26, animation: nested loop fills a times table in lesson 14:** in step „Schleife in der Schleife“, after the triangle example (which keeps the names `zeile`/`stern`), a new sentence says experienced programmers call the counters `i` and `j`, followed by an animated structure chart: the active block lights up, a variables box shows `i`, `j` and `text` (pt `texto`), and the console fills line by line with `1 2 3 4`, `2 4 6 8`, `3 6 9 12`. It shows that `j` starts again at 1 on every new line. Plays once when visible, „Noch einmal abspielen“ replays it (de/en/pt).
- **Web 0.14.25, „Bombe entschärfen“: tap part of a line:** a bomb round can name the wrong part with `stelle:` (e.g. `stelle: i++`). Such rounds show the parts of every line as tappable boxes (the three fields of a `for` header, the condition of `if`/`while`, target and value of an assignment, call and arguments split at `+`); right line but wrong part gives its own hint. Lesson 13 (6 of 8 rounds) and lesson 15 (all 6 rounds) use it (de/en/pt, texts in all 21 languages).
- **Web 0.14.24, animation: while becomes for in lesson 13:** step 2 „Zählen mit festem Plan“ of the for loop lesson shows an animated structure chart: the while loop's start value (`int i = 1`), condition (`i <= 5`) and step (`i++`) light up one after another in their own colour and then move together into the head of the for loop, labelled Start, Bedingung, Schritt (en Init/Condition/Step, pt Início/Condição/Passo). It plays once when it scrolls into view; „Noch einmal abspielen“ replays it. With reduced motion only the end state is shown. New lesson block `::: grafik datei.svg animiert` (own SVG with CSS animation, no library).
Expand Down
4 changes: 4 additions & 0 deletions web/lessons/de/begriffe.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ Ein eigenes Struktogramm für eine Teilaufgabe. Es wird mit einem Aufruf ausgef
auch: Parametern
Eine Variable in der Kopfzeile eines Unterprogramms. Beim Aufruf bekommt sie den Wert aus den Klammern.

### Überladung
auch: überladen, überladene, überladenen, overloading
Mehrere Methoden mit demselben Namen, aber verschiedenen Parametern, z. B. `mbot.forward(30)` und `mbot.forward(2, "Umdrehungen")`. Java wählt beim Aufruf die passende nach Anzahl und Typ der Parameter.

### Spaghetticode
Ein Programm, das so kreuz und quer springt, dass man den Ablauf kaum noch verfolgen kann. Struktogramme verhindern das.

Expand Down
50 changes: 50 additions & 0 deletions web/lessons/de/visubot/22-eigene-methoden.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ kurz: Eigene Befehle mit Parametern und Rückgabewert schreiben und aufrufen.
::: kompetenzen
- ein Unterprogramm mit Parameter bauen und aufrufen
- Methoden in Java erkennen
- eine überladene Methode erkennen und aufrufen
- eine Methode mit Rückgabewert schreiben
:::

Expand Down Expand Up @@ -70,6 +71,54 @@ Im Bereich [Code](#zeige-codelive) siehst du jede Methode in ihrem eigenen Reite
> Der Wert in den Klammern des Aufrufs wird zum Parameter `seite`.
:::

## Gleicher Name, andere Parameter: Überladung

Du kennst `mbot.forward()` und `mbot.forward(30)`. Das sind **zwei verschiedene Methoden mit demselben Namen**. Java erkennt am Aufruf, welche gemeint ist: an der **Anzahl** und am **Typ** der Parameter. Das nennt man **Überladung** (englisch *overloading*).

Es gibt noch eine dritte `forward`-Methode. Sie hat zwei Parameter: eine Zahl und eine **Einheit** als Text.

```java
mbot.forward(); // 10 cm (Standardwert)
mbot.forward(30); // 30 cm
mbot.forward(30, "cm"); // 30 cm, Einheit ausdrücklich
mbot.forward(2, "Umdrehungen"); // die Räder drehen sich zweimal
```

Eine Radumdrehung ist so weit wie der Umfang des Rads: π · 6,5 cm ≈ 20,4 cm. Zwei Umdrehungen sind also etwa 40,8 cm. Für `mbot.backward` gibt es dieselben drei Varianten.

So sehen die drei Kopfzeilen aus. Der Methodenname ist gleich, die Parameterlisten sind verschieden:

```java
void forward()
void forward(int cm)
void forward(int wert, String einheit)
```

Überladung kennst du schon: `System.out.println` gibt es für `int`, für `double`, für `String` und noch mehr. Deshalb kannst du jeden dieser Werte einfach in die Klammern schreiben.

::: angeberwissen
Stimmen die 20,4 cm bei **deinem** mBot2 wirklich? Profis glauben keiner Zahl, die sie nicht nachgemessen haben. Miss den Raddurchmesser und lass `mbot.forward(5, "Umdrehungen")` fahren: Soll sind 102,1 cm. So testet man Softwaresysteme: Jeder **Testfall** hat ein erwartetes Ergebnis (**Soll**) und ein gemessenes (**Ist**). Man testet mehrmals und schreibt alles in ein **Protokoll**. Hier ist dein [Messprotokoll zum Ausdrucken (PDF)](https://visustruct.org/visubot/messprotokoll-radumdrehung.pdf). Gib es deiner Lehrkraft, dann sieht sie, ob alle Roboter gleich weit fahren.
:::

::: übung vb-ueberladung-umdrehung
titel: Quadrat mit Umdrehungen
auftrag: Fahre ein Quadrat, bei dem jede Seite genau **eine Radumdrehung** lang ist. Nimm dafür die überladene Methode `mbot.forward(1, "Umdrehungen")`.
fahrt: 4 x (forward 20.42, turnRight)
braucht: forSchleife
tipp: Eine For-Schleife mit `int i = 0`, `i < 4`, `i++`.
tipp: Im Inhalt stehen `mbot.forward(1, "Umdrehungen")` und `mbot.turnRight()`.
lösung: vb-ueberladung-umdrehung-loesung.visustruct
:::

::: quiz
? Welche Methode ruft `mbot.forward(3, "Umdrehungen")` auf?
→ Gleicher Name, andere Parameter: Überladung
- [ ] `forward()`
- [ ] `forward(int cm)`
- [x] `forward(int wert, String einheit)`
> Java wählt die Variante, deren Parameter passen: zwei Parameter, eine Zahl und ein Text.
:::

## Jetzt ohne Roboter: Methode mit Rückgabe

Eine Methode kann auch etwas **ausrechnen** und das Ergebnis zurückgeben. Statt `void` steht dann der Datentyp des Ergebnisses in der Kopfzeile, und `return` gibt den Wert zurück:
Expand Down Expand Up @@ -98,5 +147,6 @@ Schätze dich bei jedem Punkt ehrlich ein: ☂️ noch nicht, ⛅ teilweise, ☀
::: checkliste
- Ich kann ein Unterprogramm mit Parameter bauen und aufrufen. → Ein Unterprogramm für das Quadrat
- Ich kann Methoden in Java erkennen. → Methoden in Java
- Ich kann eine überladene Methode erkennen und aufrufen. → Gleicher Name, andere Parameter: Überladung
- Ich kann eine Methode mit Rückgabewert schreiben. → Jetzt ohne Roboter: Methode mit Rückgabe
:::
4 changes: 4 additions & 0 deletions web/lessons/de/visubot/nachschlagen.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ Der mBot2 fährt geradeaus oder dreht sich auf der Stelle.
```
mbot.forward() fährt 10 cm nach vorn
mbot.forward(30) fährt 30 cm nach vorn
mbot.forward(2, "Umdrehungen") die Räder drehen sich 2-mal (≈ 41 cm)
mbot.backward(1, "Umdrehungen") eine Radumdrehung zurück (≈ 20 cm)
mbot.backward(20) fährt 20 cm zurück
mbot.turnRight() dreht sich nach rechts (90°)
mbot.turnLeft() dreht sich nach links (90°)
mbot.turnLeft(45) dreht sich nur ein bisschen nach links (45°)
mbot.turnRight(180) dreht sich ganz um
```

> `forward` und `backward` sind **überladen**: gleicher Name, verschiedene Parameter. Als Einheit gehen `"cm"` und `"Umdrehungen"`. Eine Radumdrehung sind etwa 20,4 cm.

> Ohne Zahl fährt er 10 cm oder dreht sich 90°. 90° ist ein rechter Winkel, wie die Ecke von einem Blatt Papier.

> Für ein Vieleck dreht er sich insgesamt einmal ganz herum: Dreieck 3 × 120°, Quadrat 4 × 90°, Sechseck 6 × 60°.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<struktogramm caption="83;113;117;97;114;101;32;119;105;116;104;32;114;111;116;97;116;105;111;110;115;">
<strelem typ="3" zx="0" zy="0">
<text>105;110;116;32;105;32;61;32;48;</text>
<text>105;32;60;32;52;</text>
<text>105;43;43;</text>
<schleifeninhalt>
<strelem typ="0" zx="0" zy="0">
<text>109;98;111;116;46;102;111;114;119;97;114;100;40;49;44;32;34;114;111;116;97;116;105;111;110;115;34;41;</text>
</strelem>
<strelem typ="0" zx="0" zy="0">
<text>109;98;111;116;46;116;117;114;110;82;105;103;104;116;40;41;</text>
</strelem>
</schleifeninhalt>
</strelem>
</struktogramm>
16 changes: 16 additions & 0 deletions web/lessons/diagramme/vb-ueberladung-umdrehung-loesung.visustruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<struktogramm caption="81;117;97;100;114;97;116;32;109;105;116;32;85;109;100;114;101;104;117;110;103;101;110;">
<strelem typ="3" zx="0" zy="0">
<text>105;110;116;32;105;32;61;32;48;</text>
<text>105;32;60;32;52;</text>
<text>105;43;43;</text>
<schleifeninhalt>
<strelem typ="0" zx="0" zy="0">
<text>109;98;111;116;46;102;111;114;119;97;114;100;40;49;44;32;34;85;109;100;114;101;104;117;110;103;101;110;34;41;</text>
</strelem>
<strelem typ="0" zx="0" zy="0">
<text>109;98;111;116;46;116;117;114;110;82;105;103;104;116;40;41;</text>
</strelem>
</schleifeninhalt>
</strelem>
</struktogramm>
4 changes: 4 additions & 0 deletions web/lessons/en/begriffe.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ A structure chart of its own for part of a task. It runs when it is called. In J
also: parameter, parameters, Parameters
A variable in the header line of a subprogram. When it is called, it gets the value from the parentheses.

### Overloading
also: overloaded, overload
Several methods with the same name but different parameters, e.g. `mbot.forward(30)` and `mbot.forward(2, "rotations")`. When calling, Java picks the right one by the number and type of the parameters.

### Spaghetti code
also: spaghetti code
A program that jumps around so wildly that you can hardly follow what happens. Structure charts prevent that.
Expand Down
50 changes: 50 additions & 0 deletions web/lessons/en/visubot/22-eigene-methoden.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ kurz: Write and call your own commands with parameters and return values.
::: kompetenzen
- build and call a subprogram with a parameter
- recognise methods in Java
- recognise and call an overloaded method
- write a method with a return value
:::

Expand Down Expand Up @@ -70,6 +71,54 @@ In [Code](#zeige-codelive) you see each method in its own tab, just like in the
> The value in the brackets of the call becomes the parameter `side`.
:::

## Same name, different parameters: overloading

You know `mbot.forward()` and `mbot.forward(30)`. These are **two different methods with the same name**. Java can tell from the call which one is meant: by the **number** and the **type** of the parameters. This is called **overloading**.

There is a third `forward` method. It has two parameters: a number and a **unit** as text.

```java
mbot.forward(); // 10 cm (default)
mbot.forward(30); // 30 cm
mbot.forward(30, "cm"); // 30 cm, unit written out
mbot.forward(2, "rotations"); // the wheels turn twice
```

One wheel rotation is as far as the wheel's circumference: π · 6.5 cm ≈ 20.4 cm. So two rotations are about 40.8 cm. `mbot.backward` has the same three versions.

These are the three headers. The method name is the same, the parameter lists are different:

```java
void forward()
void forward(int cm)
void forward(int value, String unit)
```

You already know overloading: `System.out.println` exists for `int`, for `double`, for `String` and more. That is why you can simply put any of these values in the brackets.

::: angeberwissen
Are the 20.4 cm really true for **your** mBot2? Professionals don't trust a number they haven't measured. Measure the wheel diameter and run `mbot.forward(5, "rotations")`: the expected distance is 102.1 cm. This is how software systems are tested: every **test case** has an expected result and an actual (measured) result. You test several times and write everything into a **test record**. Here is your [test record to print (PDF)](https://visustruct.org/visubot/test-record-wheel-rotation.pdf). Give it to your teacher, so they can see whether all robots drive the same distance.
:::

::: übung vb-ueberladung-umdrehung
titel: Square with rotations
auftrag: Drive a square in which every side is exactly **one wheel rotation** long. Use the overloaded method `mbot.forward(1, "rotations")`.
fahrt: 4 x (forward 20.42, turnRight)
braucht: forSchleife
tipp: A for loop with `int i = 0`, `i < 4`, `i++`.
tipp: Inside are `mbot.forward(1, "rotations")` and `mbot.turnRight()`.
lösung: vb-ueberladung-umdrehung-loesung.visustruct
:::

::: quiz
? Which method does `mbot.forward(3, "rotations")` call?
→ Same name, different parameters: overloading
- [ ] `forward()`
- [ ] `forward(int cm)`
- [x] `forward(int value, String unit)`
> Java picks the version whose parameters fit: two parameters, a number and a text.
:::

## Now without the robot: a method with a return value

A method can also **calculate** something and give the result back. Instead of `void`, the header then names the data type of the result, and `return` gives the value back:
Expand Down Expand Up @@ -98,5 +147,6 @@ Rate yourself honestly for each point: ☂️ not yet, ⛅ partly, ☀️ I can
::: checkliste
- I can build and call a subprogram with a parameter. → A subprogram for the square
- I can recognise methods in Java. → Methods in Java
- I can recognise and call an overloaded method. → Same name, different parameters: overloading
- I can write a method with a return value. → Now without the robot: a method with a return value
:::
4 changes: 4 additions & 0 deletions web/lessons/en/visubot/nachschlagen.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ The mBot2 drives straight or turns on the spot.
```
mbot.forward() drives 10 cm forward
mbot.forward(30) drives 30 cm forward
mbot.forward(2, "rotations") the wheels turn twice (≈ 41 cm)
mbot.backward(1, "rotations") one wheel rotation back (≈ 20 cm)
mbot.backward(20) drives 20 cm back
mbot.turnRight() turns to the right (90°)
mbot.turnLeft() turns to the left (90°)
mbot.turnLeft(45) turns just a little to the left (45°)
mbot.turnRight(180) turns all the way round
```

> `forward` and `backward` are **overloaded**: same name, different parameters. Units are `"cm"` and `"rotations"`. One wheel rotation is about 20.4 cm.

> Without a number it drives 10 cm or turns 90°. 90° is a right angle, like the corner of a sheet of paper.

> For a polygon it turns all the way round once in total: triangle 3 × 120°, square 4 × 90°, hexagon 6 × 60°.
Expand Down
4 changes: 2 additions & 2 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "visustruct-web",
"private": true,
"version": "0.14.26",
"version": "0.14.27",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 2 additions & 0 deletions web/src/core/javaMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ const statics: Record<string, Row[]> = {
// mBot2 (siehe mbot.ts): fester Name wie `System.out`, ohne eigenes Objekt anzulegen.
mbot: [
['forward', 'cm', 'void', 'Geradeaus vorwärts fahren', 'Drive forward', 'Andar para a frente'],
['forward', 'wert, "Umdrehungen"', 'void', 'Überladen: mit Einheit "cm" oder "Umdrehungen" (1 Umdrehung ≈ 20,4 cm)', 'Overloaded: with unit "cm" or "rotations" (1 rotation ≈ 20.4 cm)', 'Sobrecarregado: com unidade "cm" ou "rotações" (1 rotação ≈ 20,4 cm)'],
['backward', 'cm', 'void', 'Rückwärts fahren', 'Drive backward', 'Andar para trás'],
['backward', 'wert, "Umdrehungen"', 'void', 'Überladen: rückwärts mit Einheit "cm" oder "Umdrehungen"', 'Overloaded: backward with unit "cm" or "rotations"', 'Sobrecarregado: para trás com unidade "cm" ou "rotações"'],
['turnLeft', 'grad', 'void', 'Auf der Stelle nach links drehen', 'Turn left on the spot', 'Rodar para a esquerda'],
['turnRight', 'grad', 'void', 'Auf der Stelle nach rechts drehen', 'Turn right on the spot', 'Rodar para a direita'],
['stop', '', 'void', 'Motoren anhalten', 'Stop the motors', 'Parar os motores'],
Expand Down
39 changes: 39 additions & 0 deletions web/src/core/mbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,45 @@ export const MBOT_STEP_CM = 10

const n = (v: number) => String(Math.round(v * 100) / 100)

/**
* Raddurchmesser des mBot2 in cm (Reifen außen, wie im 3D-Modell). Eine Umdrehung ist π · 6,5 ≈ 20,4 cm.
* Am echten Roboter rechnet die Firmware selbst in cm; bei `mbot2.straight` geben wir die umgerechnete Strecke.
*/
export const MBOT_WHEEL_DIAMETER_CM = 6.5
export const MBOT_WHEEL_CIRCUMFERENCE_CM = Math.PI * MBOT_WHEEL_DIAMETER_CM

/**
* Einheiten für die Überladung `mbot.forward(2, "Umdrehungen")` bzw. `mbot.backward(30, "cm")`:
* Faktor in cm und die Wörter für die Konsole.
*/
const DRIVE_UNITS: Record<string, { cm: number; one: string; many: string }> = {
cm: { cm: 1, one: 'cm', many: 'cm' },
umdrehungen: { cm: MBOT_WHEEL_CIRCUMFERENCE_CM, one: 'Umdrehung', many: 'Umdrehungen' },
umdrehung: { cm: MBOT_WHEEL_CIRCUMFERENCE_CM, one: 'Umdrehung', many: 'Umdrehungen' },
rotations: { cm: MBOT_WHEEL_CIRCUMFERENCE_CM, one: 'rotation', many: 'rotations' },
rotation: { cm: MBOT_WHEEL_CIRCUMFERENCE_CM, one: 'rotation', many: 'rotations' },
'rotações': { cm: MBOT_WHEEL_CIRCUMFERENCE_CM, one: 'rotação', many: 'rotações' },
'rotação': { cm: MBOT_WHEEL_CIRCUMFERENCE_CM, one: 'rotação', many: 'rotações' },
}

/** Erlaubte Einheiten (für Fehlermeldungen). */
export const MBOT_DRIVE_UNITS = ['cm', 'Umdrehungen', 'rotations'] as const

/**
* `mbot.forward(2, "Umdrehungen")`: Fahrt mit Einheit. Die Aktion speichert wie `forward(41)` die Strecke in cm,
* damit Simulation, Übungsprüfung und echter Roboter nichts Neues lernen müssen; nur die Konsole nennt die Umdrehungen.
* `undefined`, wenn die Einheit unbekannt ist.
*/
export function makeMBotDriveAction(method: 'forward' | 'backward', value: number, unit: string): MBotAction | undefined {
const u = DRIVE_UNITS[unit.trim().toLowerCase()]
if (!u) return undefined
const cm = value * u.cm
const action = makeMBotAction(method, [cm])
if (u.cm === 1) return action
const word = value === 1 ? u.one : u.many
return { ...action, label: `${n(value)} ${word} ${method === 'forward' ? 'vorwärts' : 'rückwärts'} (${n(cm)} cm)` }
}

/** Befehle (Anweisungen). Drehen: positiver Winkel bei `mbot2.turn` dreht nach rechts. */
export const MBOT_COMMANDS: Record<string, CommandSpec> = {
forward: { args: 1, defaults: [MBOT_STEP_CM], python: ([cm]) => `mbot2.straight(${n(cm)})`, label: ([cm]) => `${n(cm)} cm vorwärts` },
Expand Down
Loading
Loading