Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java assignment: Overview In this assignment, you will write several methods that process arrays in various ways. You will also write a simple main method

Java assignment:

Overview

In this assignment, you will write several methods that process arrays in various ways. You will also write a simple main method to invoke these methods for testing purposes. zyBooks will test your methods independently.

Code Organization

Create an Eclipse project called Array Methods, and inside the project, create a new class called ArrayMethods. At the top of the file, write a comment block with your name, date, and time spent on the assignment. Also inside this comment block, list any persons or resources that assisted you in completing the assignment.

Instructions

You must complete the class ArrayMethods which has eight methods (including main). The programs main method is just for you to test the other seven methods. zyBooks will make sure you have a main method, but it will test your other methods independently. This means you can get partial credit for completing some of the methods. If you can't complete all of them, write an empty method stub so that the test code does not crash.

Program Requirements

Write these eight methods:

A main method that creates some test arrays and passes them to your other three methods in various ways for testing. No scanning is required; its easiest to create the arrays manually using initializer lists (look it up).

public static int countEvens(int[] a) Use the exact method header given. Return the number of even numbers in the array passed in to the method.

public static double average(int[] a) Use the exact method header given. Return the average of the numbers in the array passed in to the method.

public static boolean isSorted(int[] a) Use the exact method header given. Return true if the values in the array passed in to the method are sorted in ascending order. Return false if they are not.

public static void reverse(int[] a) Use the exact method header given. Reverse the passed-in array in place.

public static String toString(int[] a) Use the exact method header given. Return a String containing the contents of the array, separated by commas and spaces, with square brackets around the collection. Make sure there is no comma or space after the last item. For example: [1, 2, 3, 4, 5]

public static void sort(int[] a) Use the exact method header given. Sort the array in place using either insertion sort or selection sort. You may not call any other methods by your sort method.

public static int binarySearch(int[] a, int target) Use the exact method header given. Assume the passed-in array is sorted and return the index of the target in the array if it is found. If it is not found, return -1 instead.

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

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions