To complete the assignment, complete the file called containing the Hw2 class containing the methods as described below. You should submit ONLY the file. You will complete the file by writing the following methods:

public static void printArray(double [] output): The method prints the elements of the array output to the standard output, all elements on one line with spaces between them and a newline following the last element.

public static double[] enterMeasure(): The method first opens a Scanner object. It then repeatedly prompts the user to enter the number of elements that will be placed into the array. When the user enters a positive (> 0) value, the method creates a new array of doubles of this size. It then prompts the user to enter values into this array. The values entered into the array must be doubles and must be non-negative (>= 0). If the user enters a negative value, the value is not placed into the array. As soon as the entire array is filled, the method closes the Scanner object and returns the array it created.

public static double findAvg(double[] measure) throws IllegalArgumentException: The method first checks if the parameter array is empty, e.g. has size 0. If it does, the method throws an IllegalArgumentException with an appropriate message (see below). If the array has elements in it, the method creates a loop to sum them. If at any point in that loop a negative measurement is found in the array, the method throws an IllegalArgumentException with an appropriate message (see below). If the method only finds non-negative (>= 0) values, it returns the sum of all the values in the array divided by the number of values that are found in the array.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

package hw2;
import java.util.*;

// Put your name here
// Put your collaboration statement here

public class Hw2 {

// Do not modify this method except to uncomment/comment lines
public static void main(String[] args) {
      double [] rainfall = enterMeasure();
      System.out.println("The rainfall measurements:");
      System.out.println("The average rainfall is: " + findAvg(rainfall));
      // Two arrays that will cause problems -- put them into your code to test that...

By purchasing this solution you'll be able to access the following files:
Solution.jpg and

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats