Objectives Alter bepaald be .thewarded with Codec Den frihet - Aaraa dah tab Exercises Drobeecrets With TM ON The orcion
Posted: Sat Nov 27, 2021 2:15 pm
Objectives: After the completion of this lab, students should be able to: • Use user-defined methods • Call methods and pass references to them • Declare and create arrays of primitive and reference data types • Access and process array elements sedah Lab Exercises: Problem Description: Write a Java program that has two classes: TestOddNumbers and OddNumbers. The former class contains ONLY the main method. In this method. you are asked to write the necessary code for creating a one-dimensional integer array, int Array, and initializing its entries with the following elements: (2, 3, 5, 4, 10, 15, 12, 7, 9). In the latter class, you are asked to write the following static methods that manipulate this array: 1. Method name: countOddNumbers Parameters: int[] a Return: int Logic: counts the oda bers in the array a and returns the number of odd values 2. Method name: sumOddNumbers. Parameters: inta Return: int Logic: computes the sum of the odd numbers in the array a and returns the summation 3. Method name: averageOddNumber. Parameters: int all Return: double Logic: computes the average of the odd numbers in the array a and returns the average Hint: call the method sumOddNumbers to compute the sum of the odd numbers in the array a and then divide the retumed value by the count of Odd numbers 2011 Dr. Abdulbaset Gaddah, <Computer Programming > 11)
Lab 12: Arrays 4. Method name: largestOddNumber. Parameters: int all Return: String Logic: finds and returns the largest odd number in the array a. If odd numbers cannot be found this method should return the following text "Odd Numbers are NOT Available". Hint: you need to use String.valueOf(largestNum). if you find the largest odd number. 5. Method name: smallestOddNumber. Parameters: int all Retum: String Logic: finds and returns the smallest odd number in the array a. If odd numbers cannot be found, this method should return he following text "Odd Numbers are NOT Available" Hint: you need to use String.valueOf(smallestNum). if you find the smallest odd number. 6. Method name: count MultipleOfNumberFive. Parameters: int all Return: int Logic: counts the numbers that are divisible by number S in the array a and returns the total count Wah Write the necessary code in the main method that tests all the described methods and clearly prints out the returned results in the format shown below: Sample output: ATEN 7.8 There are 5 odd numbers The sum of odd numbers is 39 The average of odd numbers is The largest odd number is 15 The smallest odd number is 3 There are 3 numbers dividable by 5