Skip to content

Commit

Permalink
Add average two numbers assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahsnider committed Jun 11, 2024
1 parent 014fd29 commit 445b198
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/src/main/java/assignments/variables1/AverageTwoNumbers.java
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);
}
}

0 comments on commit 445b198

Please sign in to comment.