Question: Java question on using API to implement isNan and isInfinity to pass the test. I'm a Java beginner. I'm given the task to implement isNan
Java question on using API to implement isNan and isInfinity to pass the test.
I'm a Java beginner. I'm given the task to implement isNan and isInfinity, but I have no idea how to do this with API.

The giving task is as follow:

Here is the test so that it's convenient for you to copy and paste. Thank you.
@Test void should_judge_special_double_cases() { // Hint, please implement isInfinity and isNan in this class. assertTrue(isInfinity(1d / 0d)); assertTrue(isInfinity(-1d / 0d)); assertFalse(isInfinity(2d)); assertFalse(isInfinity(Double.NaN)); assertTrue(isNan(0d / 0d)); assertFalse(isNan(Double.NEGATIVE_INFINITY)); assertFalse(isNan(Double.POSITIVE_INFINITY)); }@SuppressWarnings ("unused") private boolean isNan(double realNumber) { // TODO: // please implement the method to pass the test. It is better you call existing // API rather than implemented yourself. } /unused/ private boolean isInfinity(double realNumber) { // TODO: // please implement the method to pass the test. It is better you call existing // API rather than implemented yourself. } @Test void should_judge_special_double_cases() { // Hint, please implement isInfinity and isNan in this class. assertTrue(isInfinity( realNumber: 10 / 0d)); assertTrue(isInfinity( realNumber: -10 / d)); assertFalse(isInfinity( realNumber: 2d)); assertFalse(isInfinity (Double. NaN)); assertTrue(isNan( realNumber: d / d)); assertFalse(isNan(Double. NEGATIVE_INFINITY)); assertFalse(isNan(Double.POSITIVE_INFINITY)); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
