Assessment 2_8_sample
Instructions
This assessment is designed to be completed in 20 minutes or less.
Copy the template below and get all the test cases to pass. Hard-coding answers will not receieve credit; your solution must work for valid boards of arbitrary size.
The problem
Imagine that the user specifies with width and height of a grid, and provides a tile in that grid. You will write code to return the sum of the adjacent neighbors of that tile that are directly above, or to the left and right. For example, in the grid below,
tiles 23 will would return the list [16, 30, 22, 24] which sums to 92 and tile 70 would return the list [63, 0, 69, 0], which sums to 132. If a neighbor doesn’t exist, you should return a 0 for that item in your result array before summing.
Code Template and Test cases
public class Assess2_8_Sample{
public static int plusSign(int width, int height, int tile){
int result = 0;
return result;
}
public static void main(String[] args){
System.out.println("test1: " + (plusSign(1,1,1) == 0));
System.out.println("test2: " + (plusSign(2,1,1) == 2));
System.out.println("test3: " + (plusSign(2,1,2) == 1));
System.out.println("test4: " + (plusSign(1,2,1) == 2));
System.out.println("test5: " + (plusSign(1,2,2) == 1));
System.out.println("test6: " + (plusSign(1,3,1) == 2));
System.out.println("test7: " + (plusSign(1,3,2) == 4));
System.out.println("test8: " + (plusSign(1,3,3) == 2));
System.out.println("test9: " + (plusSign(3,1,1) == 2));
System.out.println("test10: " + (plusSign(3,1,2) == 4));
System.out.println("test11: " + (plusSign(3,1,3) == 2));
System.out.println("test12: " + (plusSign(2,3,1) == 5));
System.out.println("test13: " + (plusSign(2,3,2) == 5));
System.out.println("test14: " + (plusSign(2,3,3) == 10));
System.out.println("test15: " + (plusSign(2,3,4) == 11));
System.out.println("test16: " + (plusSign(2,3,5) == 9));
System.out.println("test17: " + (plusSign(3,2,1) == 6));
System.out.println("test18: " + (plusSign(3,2,2) == 9));
System.out.println("test19: " + (plusSign(3,2,3) == 8));
System.out.println("test20: " + (plusSign(3,2,4) == 6));
System.out.println("test21: " + (plusSign(3,2,5) == 12));
System.out.println("test22: " + (plusSign(3,2,6) == 8));
System.out.println("test23: " + (plusSign(3,3,1) == 6));
System.out.println("test24: " + (plusSign(3,3,2) == 9));
System.out.println("test25: " + (plusSign(3,3,3) == 8));
System.out.println("test26: " + (plusSign(3,3,4) == 13));
System.out.println("test27: " + (plusSign(3,3,5) == 20));
System.out.println("test28: " + (plusSign(3,3,6) == 17));
System.out.println("test29: " + (plusSign(3,3,7) == 12));
System.out.println("test30: " + (plusSign(3,3,8) == 21));
System.out.println("test31: " + (plusSign(3,3,9) == 14));
System.out.println("test32: " + (plusSign(5,5,2) == 11));
System.out.println("test33: " + (plusSign(5,5,19) == 76));
System.out.println("test34: " + (plusSign(5,5,13) == 52));
System.out.println("test35: " + (plusSign(5,5,25) == 44));
}
}