1 initialize(parameters) Takes an array of integers and initialize each element with a random number between 1 and 10. Use: Create an array of 10 integers in the main method, and pass the array to this method for initialization. 2 printArray (parameters) Takes an array of integers and prints the contents of the array one element in each line. Use: Pass the array created in item#1 to this f method. 3 reverseArray (parameters) Reverse contents of a given array of integers. Use: Pass the array created in item#1 to this method to reverse its contents, and then pass it to method printArray( …) to print its contents. 4 sumArray (parameters) Takes two arrays of integer with the same size, and sum elements of 0 to j of the first array, and put the result into j element of the second array. For example, if first array is {4, 6, 3, 5}; the contents of the second array will be {4, 10, 13, 18} Use: create a new array of integers with the same size of the array created in item#1. Pass both arrays to this method, and print the content of the second array 5 itilialize (parameters) Create another method initialize() (overload method created in item1) to take an array of integers and two values downLimit and upLimit to initialize each elements of the array to a random number between downLimit and upLimit. (Think about generalization) Use: Create a new array of integers with the 50 elements and initialize its contents to a random value between 10 to 20. 6 countArray (parameters) Takes the array created in item#5, and counts how many times each number occurred in the array, and then print the result. For example: if the given array is {12, 11, 15, 12, 11, 12} then the output should be 11 occurs = 2 12 occurs = 3 12 occurs = 1 7 readArray (parameters) Create an array of 256 characters , and read a message character by character from keyboard and store them in the array up to 256 symbols.(Use sample code for lab#6 to read a message from keyboard character by character). The method should return number of the characters stored in the array. Note: We will talk about partially filled array next week. 8 printOneInLine(parameters) Pass the array created in item 7 to print each word of the message in a line. Note 2: The main method of the program should look something like the following code. public static void main(String[] args) { int[] arrItem1 = new int[10]; int arrItem4 = new int[10]; int arrItem5 = new int [50]; char arrItem7 = new char[256]; int size; initialize(arrItem1); // Item 1 printArray(arrItem1); // Item 2 reverseArray(arrItem1); // Item 3 printArray(arrItem1); sumArray(arrItem1); // Item 4 printArray(arrItem4); initialize(arrItem5, 10, 20); // Item 5 countArray(arrItem5); // Item 6 readArray(arrItem7); // item 7 printOneInLine(arrItem7); // item 8 } Note 3: We will continue discussion on arrays this week. Note 4: Remember that this lab will be marked from 80. Note 5: Write your algorithm in pseudo code only for items 3, 4, 6, and 8.
Array Operations
1 initialize(parameters) Takes an array of integers and initialize each element with a random number between 1 and 10. Use: Create an array of 10 integers in the main method, and pass the array to this method for initialization. 2 printArray (parameters) Takes an array of integers and prints the contents of the array one element in each line. Use: Pass the array created in item#1 to this f method. 3 reverseArray (parameters) Reverse contents of a given array of integers. Use: Pass the array created in item#1 to this method to reverse its contents, and then pass it to method printArray( …) to print its contents. 4 sumArray (parameters) Takes two arrays of integer with the same size, and sum elements of 0 to j of the first array, and put the result into j element of the second array. For example, if first array is {4, 6, 3, 5}; the contents of the second array will be {4, 10, 13, 18} Use: create a new array of integers with the same size of the array created in item#1. Pass both arrays to this method, and print the content of the second array 5 itilialize (parameters) Create another method initialize() (overload method created in item1) to take an array of integers and two values downLimit and upLimit to initialize each elements of the array to a random number between downLimit and upLimit. (Think about generalization) Use: Create a new array of integers with the 50 elements and initialize its contents to a random value between 10 to 20. 6 countArray (parameters) Takes the array created in item#5, and counts how many times each number occurred in the array, and then print the result. For example: if the given array is {12, 11, 15, 12, 11, 12} then the output should be 11 occurs = 2 12 occurs = 3 12 occurs = 1 7 readArray (parameters) Create an array of 256 characters , and read a message character by character from keyboard and store them in the array up to 256 symbols.(Use sample code for lab#6 to read a message from keyboard character by character). The method should return number of the characters stored in the array. Note: We will talk about partially filled array next week. 8 printOneInLine(parameters) Pass the array created in item 7 to print each word of the message in a line. Note 2: The main method of the program should look something like the following code. public static void main(String[] args) { int[] arrItem1 = new int[10]; int arrItem4 = new int[10]; int arrItem5 = new int [50]; char arrItem7 = new char[256]; int size; initialize(arrItem1); // Item 1 printArray(arrItem1); // Item 2 reverseArray(arrItem1); // Item 3 printArray(arrItem1); sumArray(arrItem1); // Item 4 printArray(arrItem4); initialize(arrItem5, 10, 20); // Item 5 countArray(arrItem5); // Item 6 readArray(arrItem7); // item 7 printOneInLine(arrItem7); // item 8 } Note 3: We will continue discussion on arrays this week. Note 4: Remember that this lab will be marked from 80. Note 5: Write your algorithm in pseudo code only for items 3, 4, 6, and 8.