CS18000 Homework 05: Arrays

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment

Description

5/5 - (2 votes)

Introduction
As you will learn, arrays are a very powerful feature, and are used throughout the Java
Language and Platform. An array is a container object whose elements have a common type.
One might create an array of int, an array of Object, an array of String, etc. All of the
elements are grouped under a common name, and are accessed by indices. Do remember that
these indices start at zero in Java, as well as many other programming languages. Arrays are the
building block of many abstractions in Java, such as String, which you have already learned,
and ArrayList, which you will learn about next week.
Description
Your task for this homework is to implement eight utility methods that operate on int arrays.
A skeleton code file, IntArrayUtils.java, has been provided for you. Please do not
modify the method headers, and start writing your code where the TODO comment is located.
The format of this homework will mirror that of the midterm exams. You will be provided with a
method stub, and will have to write code that follows the specifications outlined in the JavaDoc
comment above each method. Sample usage of each method is also provided in the comment.
The methods you must declare are as follows:
➔ public static int sum(int[] anArray)
◆ Sums the values in anArray, then returns that sum
➔ public static int product(int[] anArray)
◆ Multiplies the values in anArray by each other, then returns that product
➔ public static int maxValue(int[] anArray)
◆ Returns the largest value in anArray
➔ public static int minValue(int[] anArray)
◆ Returns the smallest value in anArray
➔ public static int indexOf(int[] anArray, int value)
◆ Returns the index of the first occurrence of value in anArray, or -1 if it could
not be found
➔ public static int lastIndexOf(int[] anArray, int value)
◆ Returns the index of the last occurrence of value in anArray, or -1 if it could
not be found
➔ public static boolean equals(int[] anArray, int[]
anotherArray)
◆ Returns true if both arrays are equal, and false if they are not
➔ public static String toString(int[] anArray)
◆ Returns a String representation of anArray
Requirements
You are required to create one class, IntArrayUtils, that follows the specifications
outlined above. It is to be held in a file called IntArrayUtils.java.
NOTE: you may not use the Arrays class, the Collections class, or any other Java
collections in your implementation. Attempting to do so will waste a submission in Vocareum.
Submission
Submit your file, IntArrayUtils.java, to Vocareum through Blackboard. Keep in mind
that only your latest submission will be considered.
Rubric
– IntArrayUtils class — 100 points total
– 12.5 points each (8 total)
– sum()
– product()
– maxValue()
– minValue()
– indexOf()
– lastIndexOf()
– equals()
– toString