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.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
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.
Unlock instant AI solutions
Tap the button
to generate a solution