Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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:
anArray =
Then the sorted version of anArray would be:
sortedArray =
And reversing the sorted array would be:
reversedSorted =
Using the IDE of your choice (JGrasp is strongly recommended), create the .java class depicted in
the below UML diagram. Refer to CS110 lectures or the book for details about methods that
receive an argument and/or return a reference variable to an array. UML diagrams are explained in
lecture 19 of my cs110 course. Helpful video regarding UML diagrams
ArrayProcessor
+ sortThreeIntArray(anArray : int[]) : int[]
+ reverseThreeIntArray(anArray : int[]) : int[]
+ printThreeIntArray(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
4151
1415
1541
Page 2 of 3 CS111 Intro. Programming Fundamentals II, CWU, Tatiana Harrison, Lab 1
sortThreeIntArray 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 sortThreeIntArray and reverseThreeIntArray,
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 youll learn about in CS301 and CS302.
However, you dont 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 youll 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 youd check whether 1<6, and
then whether 6<3, and perform swapping when necessary to rearrange the entries to 1,3,6. You
are not allowed to use the Sort method.
II. The ArrayProgram class
Write a class, ArrayProgram, with a main routine that has the below pseudocode. Youll need
to import the Random class and generate numbers with an upper bound.
// create an array, anArray, of 3 ints
// create an instance of the Random class
// create an instance of the ArrayProcessor class
// generate a random number between 0 and 100, and place it into the 0th index of anArray
// generate a random number between 0 and 100, and place it into the 1st index of anArray
// generate a random number between 0 and 100, and place it into the 2nd index of anArray
// invoke the printThreeIntArray method of the ArrayProcessor class and print the anArray entries
// invoke sortThreeIntArray method of the ArrayProcessor class, and print the sorted array
// invoke the reverseThreeIntArray method of the ArrayProcessor class, and print the reversed array
III. Sample Invocation
Three sample invocations of the program are shown below.
The original array
Entry 0 is 81
Entry 1 is 23
Entry 2 is 95
The sorted array
Entry 0 is 23
Entry 1 is 81
Entry 2 is 95
The sorted reversed array
Entry 0 is 95
Entry 1 is 81
Entry 2 is 23
The original array
Entry 0 is 63
Entry 1 is 5
Entry 2 is 63
The sorted array
Entry 0 is 5
Entry 1 is 63
Entry 2 is 63
The sorted reversed array
Entry 0 is 63
Entry 1 is 63
Entry 2 is 5
The original array
Entry 0 is 71
Entry 1 is 5
Entry 2 is 0
The sorted array
Entry 0 is 0
Entry 1 is 5
Entry 2 is 71
The sorted reversed array
Entry 0 is 71
Entry 1 is 5
Entry 2 is 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is a credit limit? How can you increase your credit limit?

Answered: 1 week ago