Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please test your program before submitting. I will give you a bad mark if it doe

ID: 3533073 • Letter: P

Question

Please test your program before submitting. I will give you a bad mark if it doesn't work.




Description:
This assignment will test your understanding of arrays.


Write a static method minGap that takes an integer array as a parameter and that returns the minimum gap
between adjacent values in the array. The gap between two adjacent values in a list is defined as the second
value minus the first value. For example, suppose a variable called "list" is an array of integers that stores the
following sequence of values.



(1, 3, 6, 7, 12)


The first gap is 2 (3 - 1), the second gap is 3 (6 - 3), the third gap is 1 (7 - 6) and the fourth gap is 5 (12 - 7).
Thus, the call:
                 minGap(list)


Should return 1 because that is the smallest gap in the list. Notice that the minimum gap could be a negative
number. For example, if list stores the following sequence of values:



(3, 5, 11, 4, 8)



The gaps would be computed as 2 (5 - 3), 6 (11 - 5), -7 (4 - 11), and 4 (8 -4). Of these values, -7 is the smallest,
so it would be returned. This gap information can be helpful for determining other properties of the list. For
example, if the minimum gap is greater than or equal to 0, then you know the list is in sorted (nondecreasing)
order. If the gap is greater than 0, then you know the list is both sorted and unique (strictly increasing).
If you are passed a list with fewer than 2 elements, you should return 0. Write your method in a class named
Gap.



Extra Credit (2 points): Write a static method printNumber that takes an array of integers that represent the
digits of a large integer and that prints the integer with commas between every 3 digits starting from the right.
You may assume that the values in the array are all between 0 and 9 and that there are no leading 0's. For
example, if the array contains the digits (1, 5, 0, 0), then your method should produce the following output:
                   1,500


If the array instead contains the digits (3, 8, 4, 9, 2, 1, 4, 7), then your method should produce the following
output:
                38,492,147


Your method might not print any commas if the number is small enough. For example, if the array contains the
digits (2, 5, 0), then your method should produce the following output:
                   250

Your method should produce an entire line of output so that if it is called several times in a row, each call will
produce a separate line of output. Write your method in a class named CommaPrinter.



Submission and Grading:
Your files Gap.java, CommaPrinter.java (if attempting extra credit) must be submitted on the course web
page. You should definitely test your code for other scenarios. There will be points taken off for not following
the conventions listed in this document regarding submissions and naming conventions. You are required to
properly indent your code and will lose points if you make significant indentation mistakes. See the textbook
for an explanation and examples of proper indentation. Give meaningful names to methods and variables in
your code. Localize variables whenever possible -- that is, declare them in the smallest scope in which they are
needed.
Include a comment at the beginning of your program with basic information and a description of the program
and include a comment at the start of each method. Your comments should be written in your own words and
not taken directly from this document.

Explanation / Answer

//please rate


Gap.java

http://ideone.com/4zdkpY


CommaPrinter.java

http://ideone.com/xcoJTA