Question: Block world In this task you are implementing a class BlockWorld in package com.labs. lab4 that simulates a block- world. The blockworld is an x

Block world In this task you are implementing a class BlockWorld in package com.labs. lab4 that simulates a block- world. The blockworld is an x n grid two-dimensional grid whose cells can either be colored black or white. n is a parameter that can be set when a blockworld is created. Initially, when a block world is created all cells are black. The BlockWorld class should have two constructors. One that takes parameter n and a second one that takes no parameters and creates a grid with n=10. The block world should provide methods for changing the color at a certain position and to get the color at a certain position which have the following signatures. Assume that the color of a cell is represented as a boolean value where true means white and false means black. public boolean get Cell Color (int n, int y): public void setCellColor (int x, int y, boolean setWhite) The class should override the toString method to return the current state of the grid where each row of the grid should be printed on a separate line while each cell would be encoded as a single character: ."" (a space) if the cell is white . "X" (an X) if the cell is black For example, a 3 x 3 grid where only the top-left and the bottom-right cells are white should be represented as: XX XXX XX Test your block world by adding a main method which creates the above example 3-by-3 grid and prints the state: BlockWorld n = new BlockWorld (3); n.setCellColor(0,0, true); // set top-left cell n.setCellColor (2,2, true); // set bottom-right cell System.out.println(n.toString()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
