Answered step by step
Verified Expert Solution
Question
1 Approved Answer
N eed help with java on eclipse. Assignment 5: Integer Array Class This assignment asks you to write a collection of little functions that all
Need help with java on eclipse.
Assignment 5: Integer Array Class This assignment asks you to write a collection of little functions that all operate on an array of integers. In your test class, declare and initialize two literal integer arrays in main), called sampleArrayl and sampleArray2 with the following values: intl) sampleArrayl (4,7,9,3,2,8,15,6,8,7), intll sampleArray2 (12,6,4,8,3,7,11,1,6; You will use these arrays for testing your class later on. Implement a class called IntegerArray, that has only one variable in the class which is an array of ints called arr In your main function, create one or more instances of your IntegerArray class and call each of the following methods as you implement them, For methods that return a value, the code in maint) should print the result of the call. In the IntegerArray class, only the printLiteral method should include calls to System.out 1. Implement a constructor that takes the length and create an array of that length, but does not fill t. (See 2, below, for how to fill it.) d constructor that takes an array of ints as an argument and uses it to initialize the 2. Implement a secon array of the class (kind of like a setter). The kind of copying to use here is called a "shallow copy". Use the two literals, sampleArray1 and sampleArray2, described in the first paragraph above to test this constructor 3. Create a function called printliteral() that prints the array to the console in a form that looks exactly like the literal strings use above for initialization. The literal starts with a , then lists the numbers d by commas but no spaces, and ending with ". The output must even work if the length of the array is OIor 1 (no commas). 4. Create a function called sumofAray that returns the sum of the values in the array 5. Create a function called maxlnArray that returns the maxirmum value in the array 6. Create a function called mininArray that returns the minimum value in the array. When looking for min or max, compare each new value to the min or max value that you have far. Do not initialize that value extreme (li value of the array, that value should become the min or max you have seen so far, since you haven't seen anything else. Assuming that you are using variable called minSeen, the correct solution is to initialize minSeen to the first value right away know anything about the range of possible values (which could be all negative for the initial value.] seen so e to an arbitrary extreme (like 0). Observe that when you check the first before starting the loop. That way you don't have to making 0 a had choice 2. Create a function called rangelnArray that returns the rarge of the values in the rangelnArra ange is the magnitude of the difference between the minimum and maximum [inc lusive). You compute SAMSU it by subtracting the minimum from the maximum. You already have methods that return the min and max. Use them and do not include any loops in this method. 8. Create a function called mean() that returns the average value in the array. Even though the array contains ints, return the average as a double. Note that you have a method for the sum, and you can get the length by using the array property of the array itself. So this method only has to do a divide. Test that you can get a result that includes a fractional part (not just whole numbers). You may need to look up "cast" to see how to make the division not do an integer divide. In the average and range functions, use the sumOfArray, mininArray, and maxlnArray functions to compute those parts, rather than repeating the work of computing the sum, or looking for min and max. 9. Create a function called clip that takes a maximum value as an argument and changes any value in the array that is higher than the specified maximum value to be the same as the maximum value. This function could also be called "haircut", in that it takes values that are too high, and cuts them down to the maximum allowable height. (Think of a scissor going through your hair and trimming the ones that are too long.) If the array is (2,4, 6, 7, 3), after clip(5) it should be 12, 4, 5, 5, 3 When calling the clipl) function from main(), call the print() function before and after to show the effect of clipping. Do not print values inside the clip method. If Array is empty, The min and max methods should just return 0. When you are finished (or as far as you got before getting stuck) submit the zipped package with two classes, as alwaysStep by Step Solution
There are 3 Steps involved in it
Step: 1
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