-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
014fd29
commit 445b198
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
app/src/main/java/assignments/variables1/AverageTwoNumbers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package assignments.variables1; | ||
|
||
public class AverageTwoNumbers { | ||
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv YOUR CODE vvvvvvvvvvvvvvvvvvvvvvvvvvvvv// | ||
private static int averageTwoNumbers(int firstNumber, int secondNumber) { | ||
// Compute the average of two input numbers. | ||
return 0; | ||
} | ||
|
||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ YOUR CODE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
private static void testAverageTwoNumbers(int firstNumber, int secondNumber, int expected) { | ||
double result = averageTwoNumbers(firstNumber, secondNumber); | ||
boolean pass = Math.abs(result - expected) < 0.001; | ||
System.out.printf( | ||
"averageTwoNumbers(%s, %s) -> %s | %s | %s \n", | ||
firstNumber, secondNumber, expected, result, pass ? "OK " : "X "); | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Function Call -> Expected | Yours | Pass?\n"); | ||
testAverageTwoNumbers(1, 3, 2); | ||
testAverageTwoNumbers(2, 2, 2); | ||
testAverageTwoNumbers(16, 19, 17); | ||
testAverageTwoNumbers(-581, 581, 0); | ||
} | ||
} |