Question
JAVA Language - Skeleton for the java code is below - Comment as much as possible Statistical Algorithms 1. Call each of the functions from
JAVA Language - Skeleton for the java code is below - Comment as much as possible
Statistical Algorithms
1. Call each of the functions from main() method.
2. Define the following function
-a) public static boolean isEven(int number)
--i. This function takes an integer input and returns true if the input is even, false otherwise
3. Define the following function, using isEven()
-a) public static int numberOfEvens(int[] input)
--i. This function takes an array and determines the count of even numbers seen in the array
4. Define the following function, using numberOfEvens()
-a) public static int numberOfOdds(int[] input)
--i. This function takes an array and determines the count of odd numbers seen in the array
--ii. To build this, use this formula: totalOdds = input.length numberOfEvens().
5. Define the following function, using isEven()
-a) public static double median(int[] input)
--i. This function determines the median of a given array, as defined here:
---1) If input has an odd number of elements {1,2,3}, return the middle element (2).
----a. Use isEven() to determine this.
---2) If input has an even number of elements {1,2,3,4}, return the average of the middle two elements ((2+3)/2 = 2.5)
----a. Use isEven() to determine this.
6. Return to your main() in the Exercise2.java driver and call each of the above functions to test them. Use the console to report and display the output of your tests; remember that youre graded on building the code above andbuilding the driver code to test these functions.
Skeleton of Exercise2.java
public class Exercise2 {
public static void main(String[] args) { int[] data = {1,2,3,4,5,6,9}; //note that these are already sorted for you System.out.println("Is the first array element even? " + isEven(data[0])); //System.out.println("Is the third element even? " + isEven(data[0])); //System.out.println("Number of evens in data: " + numberOfEvens(data)); //System.out.println("Number of odds in data: " + numberOfOdds(data)); //System.out.println("Median value: " + median(data)); } public static boolean isEven(int input) {//build first return false; } //todo:public static int numberOfEvens(int[] input) {//must use isEven //todo:public static int numberOfOdds(int[] input) {//must use numberOfEvens() }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started