The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
I want to know how to write the  two .java files code.
Â
II.The ArrayProcessor Class
Â
The ArrayProcessor class contains three methods. One prints the contents of an array, another sorts the contents of an array, and the third reverses the contents. The class is meant to process arrays of three ints For example, if:
|
4 |
7 |
1 |
|
 |
 |
 |
|
1 |
4 |
7 |
|
 |
 |
 |
|
7 |
4 |
1 |
anArray =
Then the sorted version of anArray would be:
sortedArray =
And reversing the sorted array would be:
reverseSorted =
Using the IDE of your choice, create the .java class depicted in the below UML diagram. Refer to sections 7.4 and 7.5 of the textbook for details about methods that receive an argument and/or return a reference variable to an array. UML diagrams are explained in section 6.2 of the book.
Â
|
ArrayProcessor |
|
               |
|
+ sort3IntArray(anArray : int[]) : int[] + reverse3IntArray(anArray : int[]) : int[] + print3IntArray(anArray : int[]) : void |
Â
Each of the three methods receives as an argument a reference variable to an array of integers. Two of the methods return a reference variable to an array object. The method
sort3IntArray returns a reference to an int array that contains the sorted, from smallest to largest, entries in the receiving anArray. Hint 1: for each of the methods sort3IntArray and reverse3IntArray, create an int array for use in that method, and populate it with entries that you retrieve from the receiving anArray object.
                                                                                                                                                                                                 Â
Hint 2: there are many ways to sort an array, which you’ll learn about in CS301. However, you don’t need a fancy algorithm to sort a small array; it can be done using a brute force approach, especially in this case because the input array that you’ll be creating will have only 3 entries. You can enumerate all of the possible combinations of entries in anArray using an if-else loop. For example, if the input array has entries 1, 6, 3, then you’d check whether 1 < 6, and then whether 6 < 3, and perform swapping when necessary to rearrange the entries to 1, 3, 6.
Â
Â
Write a class, ArrayProgram, with a main routine that has the below pseudocode. You’ll need to import the Random class and generate numbers with an upper bound (see section 4.11 of the textbook).
Â
Â
// create an array, anArray, of 3 ints
// create an instance of the Random class
Â
// generate a random number between 0 and 10, and place it into the 0th index of anArray
// generate a random number between 0 and 10, and place it into the 1st index of anArray
// generate a random number between 0 and 10, and place it into the 2nd index of anArray
Â
// invoke the print3IntArray method of the ArrayProcessor class and print the anArray entries
// invoke sort3IntArray method of the ArrayProcessor class, and print the sorted array
// invoke the reverse3IntArray method of the ArrayProcessor class, and print the reversed array
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Three sample invocations of the program are shown below.
Â
|
The original array Entry 0 is 8 Entry 1 is 2 Entry 2 is 9 Â The sorted array Entry 0 is 2 Entry 1 is 8 Entry 2 is 9 Â The sorted reversed array Entry 0 is 9 Entry 1 is 8 Entry 2 is 2 |
 |
The original array Entry 0 is 6 Entry 1 is 5 Entry 2 is 6 Â The sorted array Entry 0 is 5 Entry 1 is 6 Entry 2 is 6 Â The sorted reversed array Entry 0 is 6 Entry 1 is 6 Entry 2 is 5 |
 |
The original array Entry 0 is 7 Entry 1 is 5 Entry 2 is 0 Â The sorted array Entry 0 is 0 Entry 1 is 5 Entry 2 is 7 Â The sorted reversed array Entry 0 is 7 Entry 1 is 5 Entry 2 is 0 |
Â
                                                                                                                                                                                                 Â
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly