Hi,
I'm writing a program for my Introductory Programming class. I can't figure out how to re-combine the even and odd arrays in the problem below and it was due two day's ago! I've been trying to figure it out for 5 days now and the best I've done is to re-merge the arrays, sans the nines.
The challenge:
Define four (4) 20 element arrays, and one nine (9) element array.
Original array (20 elements)
Even number array (20 elements)
Odd number array (20 elements)
Combined ordered array (20 elements)
Counter array (9 elements)
Load the first array with random numbers in the range of 1 through 9.
Copy the numbers from the first array to the 2nd and 3rd arrays, placing even numbers in the even array, odd numbers in the odd array.
Sort the even number array in ascending order.
Sort the odd number array in ascending order.
Merge the even and odd arrays into the combined array such that the combined array is in ascending order.
Process the original array to load the counter array with a count of each digit, without using "if" or "switch" statements.
Output the results using the format in the following screen shot.
Column Headings:
none for the original array
O for odd
E for even
C for combined
Ctr for the counter array
the Histogram.
Note: Numeric arrays are automatically initialized to 0 when defined (in Java anyway). These zeros can be used for whatever purpose you might want, but are not part of the random number set generated.
I would tackle this project one step at a time. We have covered all the tools you need, now it's just a matter of bringing it all together. I expect you will have questions.
Methods are not required, but if used properly, will make for less coding, and will generally make life easier.
I do expect everyone to be able to load the 1st array with random numbers.
I expect slitting the original array into the even and odd arrays to be a challenge.
I do expect everyone to be able to sort the even and odd arrays.
I expect merging them into the combined array to be a significant challenge.
I expect loading the counter array without using if or switch statements to be a significant challenge.
I expect producing the histogram to be a significant challenge.
Do not let the merge, counter, or histogram segments prevent you from getting the other parts done.
Download and run my sample program proj9SortMergeSol.class. (Note: it must be saved under this exact name.) Also, you may experience problems running it due to your system's "path". If so, place it in the "bin" subdirectory where your compiler is located. You can run it at a DOS prompt by typing
java proj9SortMergeSol
Use the Math class random method to generate the random numbers.
You must adhere to the programming standards (see link on the project page) or I will count off.
Submit the following:
via e-mail, the source list (.java file) and a screen print
bring to class a printed hardcopy of the source list (for me to mark up with comments)