Question
In this exercise, you need to implement a class that encapsulate a Grid. Grid is a useful concept in creating board-game applications. Later we will
In this exercise, you need to implement a class that encapsulate a Grid. Grid is a useful concept in creating board-game applications. Later we will use this class to create a board game. A grid is a two-dimensional matrix (see example below) with the same number of rows and columns. You can create a grid of size 8, for example, its an 8x8 grid. There are 64 cells in this grid. A cell in the grid can have any arbitraty value. Later in this course, we will learn how to create a cell that can hold any arbirtary values. However, for the time being, we will assume that the cell-values are non-negetive integers. If a cell contains a value 0 that means, the cell is empty. To identify a cell, you need row number and column number, for example, cell (1, 3) means 3rd cell of the 1st row. You need to create a class that satisfies the following requirements.
TASK
Write tests and code for each of the following requirements, in order. The words in bold indicate message names. Whenever a requirement says the user can "ask whether...", the expected answer is boolean. Whenever a requirement speaks of a "particular" item, then that item will be an argument to the method.
1.The user can create a Grid specifying the number of row and column. Also the user can create a Grid specifying the size only.
2.The user can ask a Grid whether its isEmpty. A grid is empty when all the cells of the grid is empty.
3.The user can clear all the cells of the grid. Its a void method.
4.The user can ask a Grid whether a particular cell isValid.
5.The user can ask a Grid to set a particular value by setValue to a particular row
and col. The grid sets the value only if that cell is valid.
6.The user can ask a Grid to getValue (in this case integer) from a particular row
and col. The grid returns the value only if the locations are valid.
7.The user can ask a Grid to set part of its row and column with particular values.
Example, setCells(int rows[], int cols[], int vals[]), in this method user can specify the indexes of rows and columns that the user wants to set with some
particular values (supplied in vals array). Note that, rows, cols, and vals arrays
should be of same size.
8. Make another overridden method for setCells(int rows[], int cols[], int v), that will set particular rows and cols of a grid with a particular value.
Apart from these basic requirements, feel free to add more behaviors to the Grid class that you think appropriate. Please provide explanation for those behaviors as a comment in the source file.
Write a test class to test the behaviours of the Grid class and submit the test class as well.
Note: A grid is composed of many cells. So, you may want to decompose the grid into a Cell class that encapsulates all the necessary behaviour of a cell in the grid
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started