Question
A java class named LastnameFirstnameA2 which asks the user to define the length of an array (not more than 10) and then accept the integer
A java class named LastnameFirstnameA2 which asks the user to define the length of an array (not more than 10) and then accept the integer elements based on the length defined (No Command Line Parameters) for two arrays and follow the instructions: 2. If the length of the array is invalid or the inputs are not integers, you should print a "Usage" statement exactly as shown below. 3. If the arrays are longer than the set length, the first elements should be taken. a. For example, length = 3, input array = [1 2 3 4 5] the input should be taken as [1 2 3] 4. When inputs are correct, your file must contain the following: a. A method that returns the user's array. b. A method that prints the array passed to it. c. A method returns the sorted array of the FIRST array. Do not change the original array. Any sorting algorithm is fine but do not use APIs! Hint: You can store a copy by writing a "copy" function. d. Print this array. e. A method returns the reversed array of the SECOND array. Do not change the original array. Hint: You can store a copy by using the above written "copy" function. f. Print this array. g. A method that prints the count of even and odd numbers. h. Print the counts of even and odd numbers for both the arrays using above method. i. A method to return the sum of the elements of the array. j. Print the sum of the two arrays. Note: The print statement is different if the sum is equal and different if they are different. (Check example outputs below carefully.) 5. Pay careful attention to the above requirements. "Print" and "return" are two different things. 6. You can write additional methods or classes if needed. 7. You can use java.util.Scanner to read user input (Refer documentation https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html for more details) 8. Your output should be like the following samples. Make sure these matches EXACTLY. Also test for additional test cases to ensure the program works correctly.
Please enter the length of both the arrays: 7 Please enter 7 elements for the array: 20 30 20 44 87 10 89 90 Please enter 7 elements for the array: 12 10 35 4 31 65 45 The first input array is: [ 20 30 20 44 87 10] The second input array is: [ 12 10 35 4 31 65 45 ] The sorted first array is: [ 0 1 20 20 30 44 87 ] The second array in reverse order is: [ 45 65 31 4 35 10 12 ] In the first array, count of even numbers: 5 & count of odd numbers: 2 In the second array, count of even numbers: 3 & count of odd numbers: 4 The sum of the elements of the two arrays is 202. Program Completed.
Step by Step Solution
3.33 Rating (162 Votes )
There are 3 Steps involved in it
Step: 1
lets break down the requirements and create the LastnameFirstnameA2 class accordingly 1 Prompt the user to define the length of an array not more than 10 2 Accept integer elements based on the defined ...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