Create a JUnit testing code titled "StudentTests to test these classes, here is the code: CombineTopBottom package system; import java.util.Arrays; public class CombineTopBottom implements Diagram { privatechar[][] board; privateintanimationType; /** * Constructor that initializes the animationType with the provided parameter * value and initializes the board with the diagram resulting from calling * TwoDimArrayUtil.appendTopBottom() on the boards associated with the top and * bottom diagrams. * * @param top the top diagram * @param bottom the bottom diagram * @param animationType the animation type * @throws IllegalArgumentException if the number of columns of the top and bottom * diagrams are different */ public CombineTopBottom(Diagram top, Diagram bottom, intanimationType) { // check if the number of columns are different if (top.getNumberCols() != bottom.getNumberCols()) { thrownew IllegalArgumentException("Number of columns are different!"); }
Create a JUnit testing code titled "StudentTests to test these classes, here is the code:
CombineTopBottom
package system;
import java.util.Arrays;
public class CombineTopBottom implements Diagram {
privatechar[][] board;
privateintanimationType;
/**
* Constructor that initializes the animationType with the provided parameter
* value and initializes the board with the diagram resulting from calling
* TwoDimArrayUtil.appendTopBottom() on the boards associated with the top and
* bottom diagrams.
*
* @param top the top diagram
* @param bottom the bottom diagram
* @param animationType the animation type
* @throws IllegalArgumentException if the number of columns of the top and bottom
* diagrams are different
*/
public CombineTopBottom(Diagram top, Diagram bottom, intanimationType) {
// check if the number of columns are different
if (top.getNumberCols() != bottom.getNumberCols()) {
thrownew IllegalArgumentException("Number of columns are different!");
}
this.animationType = animationType;
// append the two diagrams vertically
board = TwoDimArrayUtil.appendTopBottom(top.getBoard(), bottom.getBoard());
}
/**
* Returns the board.
*
* @return a two-dimensional array of characters (no need to perform a deep copy)
*/
@Override
publicchar[][] getBoard() {
returnboard;
}
/**
* Returns a two-dimensional array of characters representing the next animation
* step. If the animationType is 1, the board instance variable will be updated
* by rotating the board one column to the left; if the animationType is 2, the
* board instance variable will be updated by rotating the top row.
*
* @return a reference to the updated board (no need to perform a deep copy)
*/
@Override
publicchar[][] nextAnimationStep() {
if (animationType == 1) {
// rotate the board one column to the left
board = TwoDimArrayUtil.rotateLeftOneColumn(board);
} else if (animationType == 2) {
// rotate the top row of the board
board = TwoDimArrayUtil.rotateTopOneRow(board);
}
returnboard;
}
/**
* Returns the number of rows associated with the diagram.
*
* @return the number of rows associated with the diagram
*/
@Override
publicint getNumberRows() {
returnboard.length;
}
/**
* Returns the number of columns associated with the diagram.
*
* @return the number of columns associated with the diagram
*/
@Override
publicint getNumberCols() {
returnboard[0].length;
}
}
CombineLeftRight
package system;
import java.util.Arrays;
public class CombineLeftRight implements Diagram {
private Diagram left;
private Diagram right;
privateintanimationType;
privatechar[][] board;
/**
* Constructor that initializes the animationType with the provided parameter value and initializes
* the board with the diagram resulting from calling TwoDimArrayUtil.appendLeftRight() on the boards
* associated with the left and right diagrams.
*
* @param left diagram
* @param right diagram
* @param animationType -
* @throws IllegalArgumentException if the number of rows of the left and right diagrams are different.
* Any error message is fine.
*/
public CombineLeftRight(Diagram left, Diagram right, intanimationType) {
this.left = left;
this.right = right;
this.animationType = animationType;
if (left.getNumberRows() != right.getNumberRows()) {
thrownew IllegalArgumentException("The number of rows of the left and right diagrams must be equal.");
}
this.board = TwoDimArrayUtil.appendLeftRight(left.getBoard(), right.getBoard());
}
/**
* Returns the board.
*
* @return two-dimensional array of characters (no need to perform a deep copy).
*/
@Override
publicchar[][] getBoard() {
returnboard;
}
/**
* Returns a two-dimensional array of characters representing the next animation step.
* If the animationType is 1, the board instance variable will be updated by rotating the board
* one column to the left; if the animationType is 2, the board instance variable will be updated
* by rotating the top row.
*
* @return a reference to the updated board (no need to perform a deep copy).
*/
@Override
publicchar[][] nextAnimationStep() {
if (animationType == 1) {
board = TwoDimArrayUtil.rotateLeftOneColumn(board);
} else if (animationType == 2) {
board = TwoDimArrayUtil.rotateTopOneRow(board);
}
returnboard;
}
/**
* Number of rows associated with the diagram.
*
* @return the number of rows.
*/
@Override
publicint getNumberRows() {
returnboard.length;
}
/**
* Number of columns associated with the diagram.
*
* @return the number of columns.
*/
@Override
publicint getNumberCols() {
returnboard[0].length;
}
// TwoDimArrayUtil is a utility class with static methods for manipulating two-dimensional arrays.
// It is not included here for brevity.
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps