Skip to content

Commit 6c8368f

Browse files
committed
Add B_MapCelsiusToFahrenheit.java
1 parent eae3158 commit 6c8368f

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/test/java/com/github/streams/practice/a_easy/numbers/EasyNumbersProblemSolution.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public static Map<Integer, List<Integer>> groupingOfNumbers(List<Integer> random
9595
}
9696

9797
public static long countNumberOfEvenNumbers(final List<Integer> input) {
98-
return input.stream().filter(x->x%2 ==0).count();
98+
return input.stream().filter(x -> x % 2 == 0).count();
99+
}
100+
101+
public static List<Double> convertCelsiusToFahrenheit(final List<Integer> input) {
102+
return input.stream().map(value -> (value * 9.0 / 5.0) + 32).toList();
99103
}
100104
}

src/test/java/com/github/streams/practice/a_easy/numbers/problems/A_CountEvenNumbers.java renamed to src/test/java/com/github/streams/practice/a_easy/numbers/problems/A_FilterCountEvenNumbers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Output = 3 <br>
1515
* Explanation: (1, 2, 3) are even numbers.
1616
*/
17-
class A_CountEvenNumbers {
17+
class A_FilterCountEvenNumbers {
1818

1919
@Test
2020
@Disabled
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.github.streams.practice.a_easy.numbers.problems;
2+
3+
import com.github.streams.practice.a_easy.numbers.EasyNumbersProblemSolution;
4+
import java.util.List;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.Disabled;
7+
import org.junit.jupiter.api.Test;
8+
9+
/**
10+
* Exercise focusing on the Stream.map() function. The goal is to convert a list of temperatures
11+
* from Celsius (Integers) to Fahrenheit (Doubles) using the formula:
12+
* F = (C * 9/5) + 32.
13+
* This requires using the map function to transform each element and ensure the result is collected into
14+
* a List<Double>.
15+
*/
16+
class B_MapCelsiusToFahrenheit {
17+
18+
@Test
19+
@Disabled
20+
void convertCelsiusToFahrenheit() {
21+
final var input = List.of(0, 10, 25, 37, 100);
22+
23+
final var mySolution = EasyNumbersProblemSolution.convertCelsiusToFahrenheit(input);
24+
final var yourSolution = List.<Double>of(); // WRITE YOUR IMPLEMENTATION HERE//
25+
26+
Assertions.assertEquals(
27+
mySolution,
28+
yourSolution,
29+
"Your solution is incorrect. Check the Celsius to Fahrenheit formula: F = (C * 9.0 / 5.0) + 32.");
30+
}
31+
}

0 commit comments

Comments
 (0)