Skip to content

Commit e04b7ef

Browse files
committed
test: fix cylinder surface area formula
Replaces erroneous volume calculation with correct surface area
1 parent 4d41b94 commit e04b7ef

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

β€ŽREADME.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,15 @@ Inside the `com.cbfacademy.shapes` package under the `shapes` module, create an
195195

196196
In the same package, create a concrete class `Sphere` that extends `Shape`:
197197
- `Sphere(double radius)` - constructor
198-
- `double getArea()` - overrides the base method. The value is given by the formula (`4` * `𝛑` * (`radius`<sup>2</sup>))
198+
- `double getArea()` - overrides the base method. The value is given by the formula: `4 * 𝛑 * (radius^2)` (where `radius^2` = radius<sup>2</sup>)
199199

200200
In the same package, create a concrete class `Rectangle` that extends `Shape`:
201201
- `Rectangle(double length, double width)` - constructor
202-
- `double getArea()` - overrides the base method. The value is given by the formula (`length` * `width`)
202+
- `double getArea()` - overrides the base method. The value is given by the formula: `length * width`
203203

204204
In the same package, create a concrete class `Cylinder` that extends `Shape`:
205205
- `Cylinder(double radius, double height)` - constructor
206-
- `double getArea()` - overrides the base method. The value is given by the formula (`height` * `𝛑` * (`radius`<sup>2</sup>)).
206+
- `double getArea()` - overrides the base method. The value is given by the formula: `2 * 𝛑 * radius * (height + radius)`.
207207

208208
#### :information_source: Notes
209209
Consider the appropriate visibility of all constructors, methods and instance variables

β€Žshapes/src/test/java/com/cbfacademy/shapes/ShapeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private static Stream<Arguments> getArea_CalculatesAreaCorrectly() {
4242
for (Shape shape : shapeArray) {
4343
switch (shape.getClass().getSimpleName()) {
4444
case "Cylinder":
45-
area = cylinderHeight * Math.PI * Math.pow(cylinderRadius, 2);
45+
area = (cylinderHeight + cylinderRadius) * 2 * Math.PI * cylinderRadius;
4646
break;
4747
case "Rectangle":
4848
area = rectangleLength * rectangleWidth;

0 commit comments

Comments
Β (0)