Java – Integer Array Class Assignment | Homework Help Websites

Assignment 5: Integer Array Class

Don't use plagiarized sources. Get Your Assignment on
Java – Integer Array Class Assignment | Homework Help Websites
Just from $13/Page
Order Now

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 sampleArray1 and sampleArray2 with the following values: int[] sampleArray1 = {4,7,9,3,2,8,15,6,8,7}; int[] 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 main() 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 it. (See 2, below, for how to fill it.)

professional writing services near me

2. Implement a second constructor that takes an array of ints as an argument and uses it to initialize the 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 separated by commas but no spaces, and ending with “}”. The output must even work if the length of the array is 0 (“{}”) or 1 (no commas).

4. Create a function called sumOfArray that returns the sum of the values in the array.

5. Create a function called maxInArray that returns the maximum 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 seen so far. Do not initialize that value to an arbitrary extreme (like 0). Observe that when you check the first 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 a variable called minSeen, the correct solution is to initialize minSeen to the first value right away, before starting the loop. That way you don’t have to know anything about the range of possible values (which could be all negative, making 0 a bad choice for the initial value.)

7. Create a function called rangeInArray that returns the range of the values in the array. In math, the range is the magnitude of the difference between the minimum and maximum (inclusive). You compute 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 maxInArray 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 {2, 4, 5, 5, 3}.

When calling the clip() 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.

Calculate your paper price
Pages (550 words)
Approximate price: -

Why Choose Us

Quality Papers

At Myhomeworkwriters.com, we always aim at 100% customer satisfaction. As such, we never compromise o the quality of our homework services. Our homework helpers ensure that they craft each paper carefully to match the requirements of the instruction form.

Professional Academic Writers

With Myhomeworkwriters.com, every student is guaranteed high-quality, professionally written papers. We ensure that we hire individuals with high academic qualifications who can maintain our quality policy. These writers undergo further training to sharpen their writing skills, making them more competent in writing academic papers.

Affordable Prices

Our company maintains a fair pricing system for all academic writing services to ensure affordability. Our pricing system generates quotations based on the properties of individual papers.

On-Time delivery

My Homework Writers guarantees all students of swift delivery of papers. We understand that time is an essential factor in the academic world. Therefore, we ensure that we deliver the paper on or before the agreed date to give students ample time for reviewing.

100% Originality

Myhomeworkwriters.com maintains a zero-plagiarism policy in all papers. As such, My Homework Writers professional academic writers ensure that they use the students’ instructions to deliver plagiarism-free papers. We are very keen on avoiding any chance of similarities with previous papers.

Customer Support 24/7

Our customer support works around the clock to provide students with assistance or guidance at any time of the day. Students can always communicate with us through our live chat system or our email and receive instant responses. Feel free to contact us via the Chat window or support email: support@myhomeworkwriters.com.

Try it now!

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Homework Writing Services

My Homework Writers holds a reputation for being a platform that provides high-quality homework writing services. All you need to do is provide us with all the necessary requirements of the paper and wait for quality results.

Essays

Essay Writing Services

At My Homework Writers, we have highly qualified academic gurus who will offer great assistance towards completing your essays. Our homework writing service providers are well-versed with all the aspects of developing high-quality and relevant essays.

Admissions

Admission and Business Papers

With Myhomeworkwriters.com, we will help you secure a position at your desired institution. Our essay writing services include the crafting of admissions papers. We will still help you climb your career ladder by helping you write the official papers that will help you secure a job. We will guide you on how to write an outstanding portfolio or resume.

Editing

Editing and Proofreading

Myhomeworkwriters.com has a professional editorial team that will help you organize your paper, paraphrase it, and eliminate any possible mistakes. Also, we will help you check on plagiarism to ensure that your final paper posses quality and originality.

Coursework

Technical papers

My Homework Writers harbors professional academic writers from diverse academic disciplines. As such, we can develop homework writing services in all academic areas. The simplicity or complexity of the paper does not affect the quality of homework writing services.