# CIS 357 Assignment 1

CIS 357 Assignment 1

Refer to problem 8.19 in page 314 – 315. Name your program to Homework1.java.

In addition to the given problem in the textbook, you want to provide the following additional methods:

public static int[][] generate2DArray(int row, int col)
public static void minimumConsecutiveSum(int[][] values, int num)
public static void testWithFixedValues()
public static void testWithRandomValues()

• generate2DArray() generates a two dimensional array (row X col) with array element values ranging between 0 and 9. Use the random number generator.
• minimumConsecutiveSum() finds the num consecutive numbers either horizontally, vertically, or diagonally, whose sum is minimum
• testWithFixedValues() tests the program with 6 x 7 array and fixed values of elements. Use the first array shown above. It needs to call minimumConsecutiveSum(4) to find the minimum sum of consecutive 4 numbers.
• testWithRandomValues() tests the program with number of rows and columns entered by the user. It calls generate2DArray() to generate a random 2D array. Make sure that the number of rows and columns entered by the user are greater than 4 and less than 11. It asks the user to enter num which is between 3 and 5 to find the minimum consecutive sum.
• you can add more methods if the length of any method exceeds 60 lines of code.
Ask the user for fixed value testing or random value testing. The following shows a sample output. Note that the bold face is used to indicate user input.
> java Homework1-LastName
Enter a choice: (1 for fixed value, 2 for random values) 1
Consecutive four: found ([5,0] – [5,3]) ([0,6] – [3,6]) ([3,2] – [0,5])
0 1 0 3 1 4 1
0 1 6 8 4 0 1
5 6 2 4 8 2 1
6 5 4 1 1 9 1
1 3 6 1 4 0 7
3 3 3 3 4 0 7

Minimum of consecutive four: 4 ([0,6] – [3,6])

> java Homework1-LastName
Enter a choice: (1 for fixed value, 2 for random values) 2
Enter row and column: 7 7
0 1 0 3 1 6 1
0 1 6 8 6 0 1
5 6 2 4 8 2 9
6 5 6 1 1 9 1 <== Note: your array element values should look different 1 3 6 1 4 0 7 3 3 3 2 4 0 7 1 1 1 2 1 1 3 Enter consecutive number (3, 4, 5): 6 Enter consecutive number (3, 4, 5): 3 Minimum sum of consecutive three: 3 ([6,0] – [6,2]) > java Homework1-LastName
Enter a choice: (1 for fixed value, 2 for random values) 3
Wrong input. Try again!

Enter a choice: (1 for fixed value, 2 for random values) 2
Enter row and column: 4 5
Consecutive four: found ([0,3] – [3,3])
0 1 0 2 1
0 1 6 2 6