Anita is the baby sitter of Baron Von Hauser’s kids. Von Hauser is a famous physics professor, so the Von Hauser kids have weird toys, all of which Anita has to master to be able to effectively entertain the kids.
While Anita was cleaning the bathtub she found a new toy, a Squarelotron game. It is extremely weird, and possesses a lot of mathematical symmetry. She is determined to understand this new toy, otherwise she won´t be able to play with Von Hauser’s kids. However the complexity of such an extreme toy makes it difficult to play.
A Squarelotron consist basically of a matrix of numbers. This matrix can be decomposed as square rings which can rotate independently in 4 different ways: Upside-Down (↕), Left-Right (↔), through the Main Inverse Diagonal (↙), and through the Main Diagonal (↘).
For example, consider the following Squarelotrons.

Squarelotron a) has 2 rings. The outer ring contains the numbers 1, 2, 3, 4, 5, 8, 9, 12, 13, 14, 15, 16, while the inner ring contains the numbers 6, 7, 10, 11.
Squarelotron b) has two rings and a center piece. The outer ring contains the numbers 1, 2, 3, 4, 5, 6, 10, 11, 15, 16, 21, 25, 22, 19, 24, 20, while the inner ring contains 7, 8, 9, 12, 14, 17, 18, 23. The number 13 is by itself in the center.
A Upside-Down Flip of the outer ring of Squarelotron a) yields:
A Left-Right Flip of the inner ring of squarelotron b) yields:
A Flip through the Main Inverse Diagonal of the inner ring of squarelotron a) yields:
A Flip through the Main Diagonal of the outer ring of squarelotron b) yields:
Since the squarelotron is a physical object, it can be simply rotated. For example, if the top row of the 4x4 squarelotron contains (1, 2, 3, 4) and the squarelotron is rotated right by 90 degrees, then the rightmost column of the squarelotron will contain (1, 2, 3, 4). This is not considered a "flip."
Anita wants you to do a program which performs the following. It will ask you whether to use a 4x4 or a 5x5 squarelotron, then print out the initial squarelotron (with the numbers in order, as in (a) above; (b) is slightly jumbled). Then the program will let you tell it which flips to perform, and it will print out the new squarelotron after each flip. Finally, the program will let you start with a new squarelotron, or quit.
Write and unit test the following methods. You should try using TDD, Test-Driven Design, as illustrated in class:
As before, follow the specifications exactly, because we will also be using my unit tests to check your work. Also as before, the design of the user interface is up to you--but the program must provide clear instructions on how to use it. As before, write a start() method that we can use to begin your program.
Especially if you are an experienced programmer, you may be tempted to write the methods first, and only afterwards write the unit tests. Please don't. You are in this class to learn new things, and one of the things I want you to learn is whether TDD works for you. I know it will be awkward and seems backward at first, but please give it an honest try. Who knows? You might like it.
public interface SquarelotronMethodsSmallSquarelotron and LargeSquarelotron classes.abstract class Squarelotron implements SquarelotronMethodsSmallSquarelotron and LargeSquarelotron. (There may not be very many.) This class should declare the instance variable public int[][] squarelotron, which will be inherited by each of the two subclasses. (This variable really should be private, but we need to be able to access it in order to JUnit test your methods.) main method which interacts with the user, as described above, and is the only method that does input/output. class SmallSquarelotron extends Squarelotronclass LargeSquarelotron extends SquarelotronNotice that in both the 4x4 and the 5x5 squarelotron, there are two rings that can be flipped (the center of the 5x5 ring is immobile). In each of the following methods, the ring should be one of the two strings "outer" and "inner", all lowercase, with the obvious meanings.
private SmallSquarelotron(int[] array)private LargeSquarelotron(int[] array)int[] of the correct size (either 16 or 25 numbers), initializes a squarelotron. Inside the class, represent the squarelotron as the (inherited) public int[][] squarelotron instance variable. The first four or five numbers in the array form the first row of the int[][] array, and so on. Calling the constructor should not result in any input/output.public static Squarelotron makeSquarelotron(int[] array) throws IllegalArgumentExceptionIllegalArgumentException if either of these conditions is violated. Calling this method should not result in any input/output.public int[] numbers()Given a 4x4 squarelotron, numbers returns an array of 16 numbers. Given a 5x5 squarelotron, it returns an array of 25 numbers. For a newly created squarelotron, the array returned by this method should have the same numbers in the same order as the array used to create the squarelotron. Calling this method should not result in any input/output.public Squarelotron upsideDownFlip(String ring)public Squarelotron leftRightFlip(String ring)public Squarelotron inverseDiagonalFlip(String ring)public Squarelotron mainDiagonalFlip(String ring)public Squarelotron sideFlip(String side)side should be one of the four strings "left", "right", "top", and "bottom". The two indicated columns (leftmost or rightmost), or the two indicated rows (top two rows or bottom two rows) should be interchanged.
The original squarelotron should not be modified (I will check for this). Calling this method should not result in any input/output.public void rotateRight(int numberOfTurns)numberOfTurns indicates the number of times the squarelotron should be rotated 90° clockwise. Any integer, including zero and negative integers, is allowable as the second argument. A value of -1 indicates a 90° counterclockwise rotation. This method modifies the internal representation of the squarelotron; it does not create a new squarelotron. Calling this method should not result in any input/output.@Override
public boolean equals(Object object)true if the object is a squarelotron that is equal to this squarelotron, and false otherwise. Squarelotrons that are the same except for rotations are considered equal. Squarelotrons of different sizes are never equal. Calling this method should not result in any input/output.@Override
public String toString()
this squarelotron. The returned string should contain newline characters, '\n', between rows, so that printing the returned string produces neat, good-looking output. Calling this method should not result in any input/output. You do not need to unit test this method. Eclipse can save you a lot of typing. Here's how to begin:
Squarelotron.squarelotron.SquarelotronMethods.SquarelotronMethods file. Squarelotron class. SmallSquarelotron class and the LargeSquarelotron class:
SquarelotronMethods to it, and be sure Inherited abstract methods is checked. If you do this correctly, Eclipse will generate stubs for all the methods in the interface (except equals, toString and makeSquarelotron) you will have to create these yourself). If this doesn't happen, you did something wrong; delete the class and try again. This assignment is a modified version of the problem "10016 - Flip-Flop the Squarelotron," from Online Judge.
Before 6am Friday March 29. Submit your zipped project file to Canvas. No other form of submission will be accepted.