Programming I

Northeastern Illinois University
CS200 Programming I, Spring 2017
Homework 8 Due: Friday, April 21, 2017 at 11:30 pm
Part 8a:
Create a Java class named <YourLastName>8a.
Create a main method, but for now just leave it empty.
Write the Java method below which takes an integer array a of even length and returns the
sum of the products of adjacent pairs of elements in a. Your method must work for any even
length array – you may assume the length of array a is at least 2.
For example, if a were this array:
0 1 2 3 4 5 6 7
a 10 5 100 3 6 2 30 20
Your method would compute and return the value 962, obtained by this computation:
a[0]*a[1] + a[2]*a[3] + a[4]*a[5] + a[6]*a[7] = 10(5) + 100(3) + 6(2) + 30(20)
= 50 +300 + 12 + 60
= 962
The signature of the method is:
public static int sumOfProducts( int[] a )
You may test the method from main with the sample array above if you wish to; your
implementation will be tested with other arrays that return known output.
Part 8b:
Create a Java class named <YourLastName>8b.
Create a main method, but for now just leave it empty.
Write the Java method longerTF which takes a boolean array called guess as its parameter.
The method returns true if the longest run of true values is longer than the longest run of
false values, otherwise the method returns false.
A “run” of true values is a set of adjacent cells all of which contain the value true.
For example, if guess were the array below, the length of the longest run of true values is 3,
and the length of the longest run of false values is 4, so longerTF would return false for
this example.
0 1 2 3 4 5 6 7 8 9
true false false false false true false true true true
The method signature is as follows:
public static boolean longerTF( boolean[] guess )
You may test the method from main with the sample array above if you wish to; your
implementation will be tested with other arrays that return known output.
Part 8c:
Create a class named <YourName>8c. Create a main method, but for now just leave it empty.
Write the Java method rowWithMostZeros which takes a two­dimensional array of integers
called table, and returns the index of the row which has the most zeros in it. If two or more
rows tie for the most number of zeros, return the highest index of the rows that tie.
For example, if the array table was the one given below, the method would return the value
3, since both rows 1 and 3 have three zeros, which is more than any other row, and 3 is the
largest index of all rows that tied.
0 1 2 3 4 5
0 5 3 0 0 2 2
1 0 10 0 ­5 8 0
2 1 0 ­5 10 7 7
3 1 3 4 0 0 0
4 1 0 6 4 1 1
The method signature is as follows:
public static int rowWithMostZeros( int[][] table )
You may test the method from main with the sample arrays above if you wish to; your
implementation will be tested with other arrays that return known output.
General Instructions:
No hard copies will be collected. Do not send your files through e­mail! You should submit
your work on D2L by the due date. See syllabus for late homework policy.
What to turn in:
There should be three .java files. Put all of them into a zip file and name it
<YourLastName>8.zip, and submit the zip file to the Dropbox Homework 8 folder in D2L.
Helpful Links:
How to zip files in Mac OS
How to zip files in Windows

READ ALSO :   Were the American complaints justified?