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

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

Step: 3

blur-text-image

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

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

Students also viewed these Databases questions

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Explain the procedure for valuation of shares.

Answered: 1 week ago

Question

Which months of this year 5 Mondays ?

Answered: 1 week ago

Question

Define Leap year?

Answered: 1 week ago