CPW 143 Spring 2017 Java Programming Assignment 2 Four Equal Entries


This assignment is primarily about indexing in 2D arrays.

Write a method, isAdjacentFour, that tests whether a two-dimensional array has four adjacent numbers with the same value. The method should return true if the array does have four adjacent numbers with the same value, and false otherwise.

The starter code, FourEqualEntries.java, contains all the needed test code. It has a stub for the method isAdjacentFour. Your job is to write the code that belongs inside the method isAdjacentFour.

There are 10 test cases in FourEqualEntries.java.

Three with four adjacent numbers with the same value in a row as in A below.

Three with four adjacent numbers with the same value in a column as in B below.

Two with four adjacent numbers with the same value in a diagonal as in C below.

One with four adjacent numbers with the same value in a diagonal as in D below.

One with no occurrence of four adjacent numbers with the same value.

Expected output from FourEqualEntries.java:

Test 1 = true

Test 2 = true

Test 3 = true

Test 4 = true

Test 5 = true

Test 6 = true

Test 7 = true

Test 8 = true

Test 9 = true

Test 10 = false

Submit to Canvas:

FourEqualEntries.java with method isAdjacentFour completed. Be sure to complete the header comment, indent your code correctly and use good names for variables.

Leave a Reply

Your email address will not be published. Required fields are marked *



  • File Format: .java
  • Version: 1.8.0_11