Skip to content

Commit b9bc033

Browse files
committed
Renaming a approach and some other fixes
1 parent 1b3feed commit b9bc033

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

exercises/practice/bob/.approaches/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
},
2525
{
2626
"uuid": "323eb230-7f27-4301-88ea-19c39d3eb5b6",
27-
"slug": "if-statements",
28-
"title": "if statements",
27+
"slug": "variable-based-if-statements",
28+
"title": "variable-based if statements",
2929
"blurb": "Use if statements to return the answer.",
3030
"authors": [
3131
"bobahop"

exercises/practice/bob/.approaches/introduction.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Introduction
22

3-
In this exercise, we’re working on a program to determine Bob’s responses based on the tone and style of given messages. Bob responds differently depending on whether a message is a question, a shout, both, or silence. Various approaches can be used to implement this logic efficiently and cleanly, ensuring the code remains readable and easy to maintain.
3+
In this exercise, we’re working on a program to determine Bob’s responses based on the tone and style of given messages.
4+
Bob responds differently depending on whether a message is a question, a shout, both, or silence.
5+
Various approaches can be used to implement this logic efficiently and cleanly, ensuring the code remains readable and easy to maintain.
46

57
## General guidance
68

@@ -50,9 +52,10 @@ class Bob {
5052
}
5153
```
5254

53-
This approach defines helper methods for each type of message—silent, shouting, and questioning—to keep each condition clean and easily testable. For more details, refer to the [method-based `if` Statements Approach][approach-method-if].
55+
This approach defines helper methods for each type of message—silent, shouting, and questioning—to keep each condition clean and easily testable.
56+
For more details, refer to the [method-based `if` Statements Approach][approach-method-if].
5457

55-
## Approach: `if` statements
58+
## Approach: variable-based `if` statements
5659

5760
```java
5861
import java.util.function.Predicate;
@@ -85,7 +88,7 @@ class Bob {
8588
```
8689

8790
This approach uses variables to avoid rechecking whether Bob is silent, shouting or questioning.
88-
For more details, refer to the [method-based `if` Statements Approach][approach-method-if].
91+
For more details, refer to the [variable-based `if` Statements Approach][approach-variable-if].
8992

9093
## Approach: answer array
9194

@@ -122,7 +125,7 @@ This approach uses an array of answers and calculates the appropriate index base
122125
The choice between the **Method-Based `if` Statements Approach**, **Nested `if` Statements Approach**, and the **Answer Array Approach** depends on readability, maintainability, and efficiency:
123126

124127
- **Method-Based `if` Statements Approach**: This is clear and easy to follow but checks conditions multiple times, potentially affecting performance. Storing results in variables like `questioning` and `shouting` can improve efficiency but may reduce clarity slightly.
125-
- **`if` Statements Approach**: This approach can be more efficient by avoiding redundant checks, but its nested structure can reduce readability and maintainability.
128+
- **Variable-Based `if` Statements Approach**: This approach can be more efficient by avoiding redundant checks, but its nested structure can reduce readability and maintainability.
126129
- **Answer Array Approach**: Efficient and compact, this method uses an array of responses based on flags for questioning and shouting. However, it may be less intuitive and harder to modify if more responses are needed.
127130

128131
Each approach offers a balance between readability and performance, with trade-offs in flexibility and clarity.
@@ -131,5 +134,5 @@ Each approach offers a balance between readability and performance, with trade-o
131134
[endswith]: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#endsWith(java.lang.String)
132135
[dry]: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
133136
[approach-method-if]: https://exercism.org/tracks/java/exercises/bob/approaches/method-based-if-statements
134-
[approach-if]: https://exercism.org/tracks/java/exercises/bob/approaches/if-statements
137+
[approach-variable-if]: https://exercism.org/tracks/java/exercises/bob/approaches/variable-based-if-statements
135138
[approach-answer-array]: https://exercism.org/tracks/java/exercises/bob/approaches/answer-array

exercises/practice/bob/.approaches/method-based-if-statements/content.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ class Bob {
55
String hey(String input) {
66
var inputTrimmed = input.trim();
77

8-
if (isSilent(inputTrimmed))
8+
if (isSilent(inputTrimmed)) {
99
return "Fine. Be that way!";
10-
if (isShouting(inputTrimmed) && isQuestioning(inputTrimmed))
10+
}
11+
if (isShouting(inputTrimmed) && isQuestioning(inputTrimmed)) {
1112
return "Calm down, I know what I'm doing!";
12-
if (isShouting(inputTrimmed))
13+
}
14+
if (isShouting(inputTrimmed)) {
1315
return "Whoa, chill out!";
14-
if (isQuestioning(inputTrimmed))
16+
}
17+
if (isQuestioning(inputTrimmed)) {
1518
return "Sure.";
19+
}
1620

1721
return "Whatever.";
1822
}

exercises/practice/bob/.approaches/if-statements/content.md renamed to exercises/practice/bob/.approaches/variable-based-if-statements/content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `if` statements
1+
# Variable-Based `if` statements
22

33
```java
44
import java.util.function.Predicate;

0 commit comments

Comments
 (0)