Question: In this assignment, you will learn about & practice: a variety of methods that use for loops to manipulate arrays. using code from new classes

In this assignment, you will learn about & practice:

  • a variety of methods that use for loops to manipulate arrays.
  • using code from new classes & packages to complete a task.
  • using the provided class StdAudio to manipulate audio, and the class Scanner to request user-input.
  • how to create an interactive program that runs from the main method.

Finally, you will write a program that combines these concepts to play audio in different ways based on user input.

General assignment instructions

For all required methods detailed below, it is important that their method name, return type, and parameter types exactly match the specification, in the order they are specified. You may implement additional methods if they aid your problem-solving.

Some methods are void, so they do not return anything. Instead, they do something in the method, like change the values in an array. This action is described in a Post-Condition, which describes the state of the data after the method finishes. There is not a formal Post-Condition in Javadocs, but you can add to the general description of the method.

In the descriptions of the methods below, arrays and their example values are represented with [] with a comma-separated list of values inside. You cannot call the method like that in your tests - you need to create an array, set the values of its elements, and pass the array as an argument. In other words, you cannot call a method literally like addUpValues([1,2,3,4]).

Ensure you have consistent spacing in your file, proper and consistent indenting, and meaningful variable names. Make small one line comments to describe any multi-step process in your methods.

Finally, you should only use constructs we have learned in this course to solve these problems. You should not search for "how do I replace characters in a Java String" and copy what you find. That is not getting clarification on how some small part of Java works, that is looking for a solution to the problem, which is plagiarism.

Javadoc Comments

All methods you write should have a Javadoc comment with a description of what the method does and a @param for each parameter and a @return describing what information is returned. Each class should have a Javadoc with a general description and @author tag.

Testing

Within the Loops class, add code to main to test the required methods by calling them and displaying their outputs. Your tests should cover possible return values (such as true or false), as well as special cases where allowed (for example, ""). Each test should print:

  • What method is being tested.
  • The input used for testing.
  • The method result in a neatly formatted way. Using Arrays.toString is recommended to print arrays.

Within the SmoothSounds class, your final submission should only contain the specified program code in the main method. It is OK to test your methods as you write them, but you should comment out or delete the tests before you are done.

You do not need to test for cases that are prohibited in the description. If the description says that there is at least X in the parameter, then you do not need to test for the truth of that constraint.

None of your methods except for main and (optionally) getIntFromUser may print anything to the console. While developing your other methods, you are encouraged to print values in those methods to the console to help debug your code. Those print statements in those other methods should be removed before submission.

  1. Method name: smoothArray Parameter(s): A non-null double[] with at least 3 elements in it. Return value: Returns a new double[] that has as its elements a sliding average of the parameter array elements. More precisely:
    1. The first and last elements of the new array are the same as the average of the first two and last two elements of the parameter array, respectively.
    2. For the other elements of the new array, the element at index i, is equal to the average of elements from the parameter array at indices i-1, i, and i+1.

Post-Condition: The array parameter is not changed. Example: Calling smoothArray([0.0, 0.2, 0.7, 0.2]) should return a new array [0.1, 0.3, 0.3666...,0.45]. You may see differences in your numerical values based on representational error of double numbers. Something like 0.449999999996 for 0.45 will pass the autograder tests, and is correct, even though it is unsettling to see.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!