The WalkingBoard class represents a board with a figure standing on position x,y. Each position also has a value associated with it. Initialise the board in two different ways: either make it size×size or use the given dimensions and initial values. About the second way: The rows may not be uniform: they may have differing numbers of columns in them. Don’t simply take the argument array: create its copy in the field. All values are set to BASE_TILE_SCORE, or to the given value if that’s bigger. Operations. getPosition: returns the values of x and y in an array. getTile: returns the value of the of the board position. Let this condition be checked by the helper method isValidPosition. If it is an invalid position, throw an IllegalArgumentException. getTiles: returns the values of all the board positions. Don’t let the field contents be accessed from the caller: create and return an exact copy of the structure. getXStep and getYStep: helper methods, they indicate how far (-1, 0, or 1) have to be taken to take x és y koordinátát. moveAndSet: it moves the piece and changes the value of the new position. Use the above helper methods in the code of the method. If the move would make the figure leave the board, cancel the move: the figure remains where it was, the state of the board doesn’t change at all, and the method immediately returns 0. Otherwise, the method returns the old value of the new position, and its value is set to the second argument.  setAndMove: it is similar to moveAndSet but it changes the value of the position before changing position and create 5 functional tests such that:  Where arguments are given, use a parameterized test. testSimpleInit(size): the first constructor works as expected. getTiles shows suitable values. The edges of the board (the smallest and biggest conceivable values) are accessible and contain the values that they have to (BASE_TILE_SCORE). testCustomInit(x, y, expected): the second constructor works as expected. On positions where values smaller than three were passed, the board contains the value BASE_TILE_SCORE. If you pass an array to the constructor and later modify a value in it, the respective tile retains the originally passed value. If you modify an element in the return value of getTiles(), and get the value of the respective tile again, this newly received content has to be the originally set value. testMoves(): take four or five steps and check that the board’s contents are changed just right. Include a step that tries to move to the x coordinate Integer.MIN_VALUE and another one that moves to the y coordinate 666. Include a step that tries to move outside of the board. In this case, check that both the position and the board’s contents are unchanged.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question

The WalkingBoard class represents a board with a figure standing on position x,y. Each position also has a value associated with it.

Initialise the board in two different ways: either make it size×size or use the given dimensions and initial values.

  • About the second way:
    • The rows may not be uniform: they may have differing numbers of columns in them.
    • Don’t simply take the argument array: create its copy in the field.
  • All values are set to BASE_TILE_SCORE, or to the given value if that’s bigger.

Operations.

  • getPosition: returns the values of x and y in an array.
  • getTile: returns the value of the of the board position.
    • Let this condition be checked by the helper method isValidPosition.
    • If it is an invalid position, throw an IllegalArgumentException.
  • getTiles: returns the values of all the board positions.
    • Don’t let the field contents be accessed from the caller: create and return an exact copy of the structure.
  • getXStep and getYStep: helper methods, they indicate how far (-1, 0, or 1) have to be taken to take x és y koordinátát.
  • moveAndSet: it moves the piece and changes the value of the new position.
    • Use the above helper methods in the code of the method.
    • If the move would make the figure leave the board, cancel the move: the figure remains where it was, the state of the board doesn’t change at all, and the method immediately returns 0.
    • Otherwise, the method returns the old value of the new position, and its value is set to the second argument. 
    • setAndMove: it is similar to moveAndSet but it changes the value of the position before changing position
  • and create 5 functional tests such that: 

    Where arguments are given, use a parameterized test.

    • testSimpleInit(size): the first constructor works as expected.
      • getTiles shows suitable values.
      • The edges of the board (the smallest and biggest conceivable values) are accessible and contain the values that they have to (BASE_TILE_SCORE).
    • testCustomInit(x, y, expected): the second constructor works as expected.
      • On positions where values smaller than three were passed, the board contains the value BASE_TILE_SCORE.
      • If you pass an array to the constructor and later modify a value in it, the respective tile retains the originally passed value.
      • If you modify an element in the return value of getTiles(), and get the value of the respective tile again, this newly received content has to be the originally set value.
    • testMoves(): take four or five steps and check that the board’s contents are changed just right.
    • Include a step that tries to move to the x coordinate Integer.MIN_VALUE and another one that moves to the y coordinate 666.
      • Include a step that tries to move outside of the board. In this case, check that both the position and the board’s contents are unchanged.
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT