Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 n x

image text in transcribed

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 n 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 CellColor (int x, int y); public void setCellColor (int x, inty, 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()); is set to recente right cel

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

=+j Describe the various support services delivered by IHR.

Answered: 1 week ago

Question

=+j Explain IHRMs role in global HR research.

Answered: 1 week ago