Skip to content

Commit e62d94c

Browse files
committed
added area calculation for a rhombus
1 parent 410f087 commit e62d94c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • src/main/java/com/thealgorithms/maths

‎src/main/java/com/thealgorithms/maths/Area.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,21 @@ public static double surfaceAreaCone(final double radius, final double height) {
232232
}
233233
return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5));
234234
}
235+
236+
/**
237+
* Calculate the area of a rhombus.
238+
*
239+
* @param diagonal1 length of the first diagonal
240+
* @param diagonal2 length of the second diagonal
241+
* @return area of given rhombus
242+
*/
243+
public static double surfaceAreaRhombus(final double diagonal1, final double diagonal2) {
244+
if (diagonal1 <= 0) {
245+
throw new IllegalArgumentException("Diagonal 1 must be greater than 0");
246+
}
247+
if (diagonal2 <= 0) {
248+
throw new IllegalArgumentException("Diagonal 2 must be greater than 0");
249+
}
250+
return diagonal1 * diagonal2 / 2;
251+
}
235252
}

0 commit comments

Comments
 (0)