Practice Working With Arrays And Polymorphism With Method Overloading Pass By Value And Scope Of Variables By Writing T 1 (412.75 KiB) Viewed 32 times
Practice working with arrays and polymorphism with method overloading; pass-by-value and scope of variables by writing the following methods and statements. Methods: 1. Write a method basicArray that does not take any inputs. In this method, write statements to declare an int array called nums with 50 elements. Write the statements to store the values 1 through 50 in the elements of nums, add 10 to each entry of the array nums, then print every element of nums. 2. Write a method printElements that accepts an array of Strings as the input parameter argument. The output of this function is that it will print elements of the array. Make sure that your function verifies that each element is a string type and prints those array elements to String objects. 3. Write another method printElements that accepts a two-dimensional array of ints as the input parameter argument. The output of this function is that it will print elements of the 2D array. The output should be in a matrix form (that is, with rows and columns) with each element separated by a white space. Use the printf() function to format the output with clean alignment. 4. Write a method printElements that accepts an array of Time Objects as the parameter argument. The output of this function is that it will print elements of the array. Make sure that your function verifies that each element is a Time type and prints those array elements as strings. Statements in the main method: 5. Write the statements in the main method to declare an array of 10 Strings. Store the words "first", "second", "third", "fourth", "fifth", etc. in the array, and call printElements to print your array. It should print each element followed by the length of each element. 6. Write the statements to declare an array of 3 Time objects, store a Time in each array element, and print the array. 7. Write the statements to declare a two-dimensional array of ints named values with 10 rows and 20 columns. Then write a statement that will print the number of rows in the 2D array by using the correct property that can retrieve the array size. Write a statement which will print the number of columns in a 2D array called values. Then finally write a statement that will call printElements and print the 2D array.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!