diff --git a/docs/README.md b/docs/README.md index 1ceb9c1ce..a8aa09984 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,7 @@ # Codewars Handbook ☕️🚀 [![Views statistics +1 👀](https://img.shields.io/badge/dynamic/xml?color=success&label=views&query=//*[name()=%27text%27][3]&url=https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FParanoidUser%2Fcodewars-handbook)](https://hits.seeyoufarm.com/api/count/graph/dailyhits.svg?url=https://github.com/ParanoidUser/codewars-handbook) -[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-69.3%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed) +[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-69.4%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed) [![CI pipeline 🛠](https://img.shields.io/github/actions/workflow/status/ParanoidUser/codewars-handbook/build.yml?branch=main)](https://github.com/ParanoidUser/codewars-handbook/actions/workflows/build.yml) [![Quality gate 🔎](https://img.shields.io/sonar/alert_status/codewars-handbook?server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=codewars-handbook) [![Let's have a chat! 📞](https://img.shields.io/gitter/room/ParanoidUser/codewars-handbook?color=49c39e)](https://gitter.im/ParanoidUser/codewars-handbook) @@ -25,7 +25,7 @@ slug. | [1 kyu](/kata/1-kyu/index.md) | [2 kyu](/kata/2-kyu/index.md) | [3 kyu](/kata/3-kyu/index.md) | [4 kyu](/kata/4-kyu/index.md) | [5 kyu](/kata/5-kyu/index.md) | [6 kyu](/kata/6-kyu/index.md) | [7 kyu](/kata/7-kyu/index.md) | [8 kyu](/kata/8-kyu/index.md) | [beta](/kata/beta/index.md) | [retired](/kata/retired/index.md) | |:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------------:| -| 0 | 1 | 2 | 26 | 48 | 443 | 605 | 227 | 56 | 82 | +| 0 | 1 | 2 | 26 | 48 | 443 | 605 | 228 | 56 | 82 | **Note:** The source code is written in Java 17 and may use language features that are incompatible with Java 8, 11. diff --git a/kata/8-kyu/index.md b/kata/8-kyu/index.md index e00f3f073..9dcf28fcb 100644 --- a/kata/8-kyu/index.md +++ b/kata/8-kyu/index.md @@ -167,6 +167,7 @@ - [Parse nice int from char problem](parse-nice-int-from-char-problem) - [Pillars](pillars) - [Playing with cubes I](playing-with-cubes-i) +- [Playing with cubes II](playing-with-cubes-ii) - [Plural](plural) - [Points of Reflection](points-of-reflection) - [Powers of 2](powers-of-2) diff --git a/kata/8-kyu/playing-with-cubes-ii/README.md b/kata/8-kyu/playing-with-cubes-ii/README.md new file mode 100644 index 000000000..42255037d --- /dev/null +++ b/kata/8-kyu/playing-with-cubes-ii/README.md @@ -0,0 +1,10 @@ +# [Playing with cubes II](https://www.codewars.com/kata/playing-with-cubes-ii "https://www.codewars.com/kata/55c0ac142326fdf18d0000af") + +Hey Codewarrior! + +You already implemented a Cube class, but now we need your help again! I'm talking about constructors. We don't have one. Let's code +one (or more) such that one can instantiate an object via it, handling either no arguments or a single integer. + +Also, we got a problem with negative values. Correct the code so negative values will be switched to positive ones! + +The constructor taking no arguments should assign 0 to Cube's Side property. \ No newline at end of file diff --git a/kata/8-kyu/playing-with-cubes-ii/main/Cube.java b/kata/8-kyu/playing-with-cubes-ii/main/Cube.java new file mode 100644 index 000000000..f2771117b --- /dev/null +++ b/kata/8-kyu/playing-with-cubes-ii/main/Cube.java @@ -0,0 +1,19 @@ +class Cube { + private int side; + + Cube() { + this(0); + } + + Cube(int side) { + setSide(side); + } + + int getSide() { + return side; + } + + void setSide(int side) { + this.side = Math.abs(side); + } +} \ No newline at end of file diff --git a/kata/8-kyu/playing-with-cubes-ii/test/SolutionTest.java b/kata/8-kyu/playing-with-cubes-ii/test/SolutionTest.java new file mode 100644 index 000000000..d033e21c1 --- /dev/null +++ b/kata/8-kyu/playing-with-cubes-ii/test/SolutionTest.java @@ -0,0 +1,33 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void constructor() { + assertEquals(0, new Cube().getSide()); + assertEquals(6, new Cube(6).getSide()); + assertEquals(3, new Cube(-3).getSide()); + } + + @Test + void positiveSide() { + Cube c = new Cube(); + c.setSide(3); + assertEquals(3, c.getSide()); + } + + @Test + void zeroSide() { + Cube c = new Cube(42); + c.setSide(0); + assertEquals(0, c.getSide()); + } + + @Test + void negativeSide() { + Cube c = new Cube(-42); + c.setSide(-1337); + assertEquals(1337, c.getSide()); + } +} \ No newline at end of file