Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE CODE IN JAVA!!!!! NOT C OR JAVA SCRIPT need asap! please do all and make sure they work!! public class ArrayPractice { /* sets

PLEASE CODE IN JAVA!!!!! NOT C OR JAVA SCRIPT need asap! please do all and make sure they work!!

public class ArrayPractice { /* sets every item in A[] to initialValue */ public static void initialize(int A[], int initialValue) { }

/* returns the average of the items in A * Be careful: A[] is an array of int and the method returns * double. What do we do to handle this? */ public static double average(int A[]) { return 0.0; }

/* returns the number of times that x appears in A[] */ public static int numOccurrences(int A[], int x) { return 0; }

/* returns the index of the first occurrence of * x in A[] or -1 if x doesn't exist in A[] */ public static int find(int A[], int x) { return -1; }

/* returns the index of the last occurrence of * x in A[] or -1 if x doesn't exist in A[] */ public static int findLast(int A[], int x) { return -1; }

/* returns the smallest item found in A */ public static int smallest(int A[]) { return 0; }

/* returns the index of the smallest item found in A */ public static int indexOfSmallest(int A[]) { return 0; }

/* returns the index of the smallest odd number * in A[] or -1 if A[] contains no odd numbers */ public static int indexOfSmallestOdd(int A[]) { return -1; }

/* removes the element in A[] at the given index, * by shifting all remaining elements to the left * if necessary and filling in the right-hand * side with 0s. * * returns the element removed. * * For example, if we call remove(A, 1) * on the array: * * |---+---+----+----+-----+-----+-----+---+---+---| * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | * |---+---+----+----+-----+-----+-----+---+---+---| * | 5 | 9 | 32 | 97 | 101 | 142 | 157 | 0 | 0 | 0 | * |---+---+----+----+-----+-----+-----+---+---+---| * * the array becomes: * * |---+----+----+-----+-----+-----+---+---+---+---| * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | * |---+----+----+-----+-----+-----+---+---+---+---| * | 5 | 32 | 97 | 101 | 142 | 157 | 0 | 0 | 0 | 0 | * |---+----+----+-----+-----+-----+---+---+---+---| * * * and we return the value 9. * * It is up to the caller to make sure that the * index passed to the function is valid. * */ public static int remove(int A[], int index) { return 0; }

/* returns a new array consisting of all of the * elements of A[] */ public static int[] copy(int A[]) { return null; }

/* Returns a new array consisting of all of the * elements from index s (for "start") inclusive * and index e (for "end") exclusive * * if s>e, return null * * (to do this, the syntax is really just "return null") * * for example, if the array is: * |---+----+----+----+----+----| * | 0 | 1 | 2 | 3 | 4 | 5 | * |---+----+----+----+----+----| * | 0 | 11 | 22 | 33 | 44 | 55 | * |---+----+----+----+----+----| * * with s=2 and e=5, the function returns: * |----+----+----| * | 0 | 3 | 4 | * |----+----+----| * | 22 | 33 | 44 | * |----+----+----| * */ public static int[] chunk(int A[], int s, int e) { return null; }

/* returns a new array consisting of the same elements in * A[] repeated numTimes * * for example, if A[] refers to the array: * * |----+----+----| * | 0 | 1 | 2 | * |----+----+----| * | 11 | 22 | 33 | * |----+----+----| * * and numTimes is 3, the function returns: * * |----+----+----+----+----+----+----+----+----| * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | * |----+----+----+----+----+----+----+----+----| * | 11 | 11 | 11 | 22 | 22 | 22 | 33 | 33 | 33 | * |----+----+----+----+----+----+----+----+----| * * * if numTimes <=1, the method returns a copy of A[] * */ public static int[] repeat(int A[], int numTimes) { return null; }

/* returns a new array consisting of all of the * elements of A[] followed by all of the * elements of B[]. For example, if A[] is: {10,20,30} and B[] is: {5, 9, 38}, the method returns the array : {10,20,30,5,9,38} */ public static int[] copyAll(int A[], int B[]) { return null; }

/* reverses the order of the elements in A[]. * For example, if A[] is: {10,20,30,40,50}, after the method, A[] would be {50,40,30,20,10} */ public static void reverse(int A[]) { }

/* reverses the ordering of the elements of each * row of the two-dimensionl array to which A refers. * * For example, if A refers to the array: * * * |----+----+----| * | 10 | 20 | 30 | * |----+----+----+----| * | 40 | 50 | 60 | 70 | * |----+----+----+----| * | 80 | 90 | * |----+----+ * * * the method returns: * * |----+----+----+ * | 30 | 20 | 10 | * |----+----+----+----| * | 70 | 60 | 50 | 40 | * |----+----+----+----| * | 90 | 80 | * |----+----+ * * */ public static void reverseAll(int A[][]) { }

/* scores contains a collection of quiz grades ranging * from 0 to maxScore inclusive. The method returns * a new array where the value at index i is the number * of times that grade i appeared in scores. * * For example, if scores refers to the array: * |---+---+---+----+---+---+---+---+---+---+----+----+----+----+----| * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | * |---+---+---+----+---+---+---+---+---+---+----+----+----+----+----| * | 9 | 3 | 8 | 10 | 7 | 9 | 8 | 9 | 7 | 6 | 8 | 7 | 8 | 9 | 6 | * |---+---+---+----+---+---+---+---+---+---+----+----+----+----+----| * * The method returns the array: * |---+---+---+---+---+---+---+---+---+---+----| * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | * |---+---+---+---+---+---+---+---+---+---+----| * | 0 | 0 | 0 | 1 | 0 | 0 | 2 | 3 | 4 | 4 | 1 | * |---+---+---+---+---+---+---+---+---+---+----| * * */ public static int[] counts(int scores[], int maxScore) { return null; }

/* Extra credit: * * Returns a new array consisting of all of the * elements of A, but with no duplicates. For example, * if A[] is {10,20,5,32,5,10,9,32,8}, the method returns * the array {10,20,5,32,9,8} */ public static int[] uniques(int A[]) { return null; } }

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

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions