Overview For todays lab you will create a wellcommented java

Overview For today\'s lab you will create a well-commented java project that will contain a class called Lab 01 ArrayUtilities with the following two static methods: buildIntArray and swap Also include in your project a class called Lab 01 Tester and include the main method. I will give you till Tuesday (for Thursday Labs), and Wednesday (for Friday Labs) to complete the lab, but this will not always be the case. Check the Canvas discussion board for helpful hints, and answers to questions l get from the class. Write the following code for the ArrayUtilities class methods: 1. build IntArray (int length, int fromNum, int toNum) a. The buildintArray() method should accept three parameters: 1]An array element length, 2] a \"from number, 3] and a \"to number\" so that if a call to this method looked like: buildintArray(20,5,30) an array of 20 random numbers between, and including, 5 and 30 would be returned. 2. swap (int [1 nums, int i, int j) a. The swap method will accept 3 parameters: 1] An int array; and 2,3] two variables that will represent the indices of the array whose values should be swapped. Due to the fact that java passes arrays by reference, anything you do to the array within the swap0 method changes the original array.

Solution

//Code for the first 3 queries

public class Lab_01_ArrayUtilities {
private static double[] anArray; //array declaration
public static void builtInArray(int length,int fromNum,int toNum) //static method bubiltin array
{
anArray = new int[length]; // create the Array with given length
anArray[0]=fromNum;
anArray[length-1]=toNum;
for (int i = 1; i < =length-2; i++) // create a loop to load the array
{
   anArray[i] = fromNum + (int)(Math.random()* ( toNum - fromNum + 1));//generates random number between given numbers and stores in array

}
}
public static void swap (int[] nums,int i,int j)//static method for swap
{
int[] n = int[] nums;
int temp = n[i]; // swaps n[3] and n[4]
n[i] = n[j];
n[j] = temp;
}
public static void OddNumbers(int[] nums)//OdNumbers method
{
int count =0 ;
int lenght=nums.length;
System.out.println(\"Elements in array are:\");
for(int i = 0 ; i < length; i++){
System.out.println(a[i]+\',\');
}
for(int i = 0 ; i < length; i++)
{
if(a[i] % 2 != 0)
count++;
}
       System.out.println(\"OddNumbers\"+ count);
}
public static void main(String[] args) {
   //By using class name, you can call static method
   int [ ] Array = Lab_01_ArrayUtilities.builtInArray(20,5,30);//creates array with 20 elements between 5 and 30 including 5 and 30 values in array.
   Lab_01_ArrayUtilities.swap( Array,2,3 ); ///swap 2nd 3 rd index vallues of the array object created above
   OddNumbers(Array);
}
}

 Overview For today\'s lab you will create a well-commented java project that will contain a class called Lab 01 ArrayUtilities with the following two static me

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site