Creates the Piece.java class and created the appropriate JavaDocs.

This commit is contained in:
Jonathan Turner 2024-02-02 18:36:05 -05:00
parent bd524334e8
commit 3375357755
2 changed files with 75 additions and 0 deletions

View File

@ -2,6 +2,18 @@ package Assignments.A1;
// Potentially will be changed to an UI Implementation with JavaFX if time permits. // Potentially will be changed to an UI Implementation with JavaFX if time permits.
/**
* Board will be used to save locations in a 2D array.
*
* The design of the board locations will be numbered like so:
* 0 1 2
* 3 4 5
* 6 7 8
*
* The values will be specified with an int. Must be between (inclusive) 1-8.
* The empty spot will be represented with null.
*/
public class Driver { public class Driver {

View File

@ -1,4 +1,67 @@
package Assignments.A1.models; package Assignments.A1.models;
/**
* This class allows for abstraction and proper representation of a piece of the 8 puzzle.
*
* @author Jonathan Turner
* @version CS3642 - Spring 2024
*/
public class Piece { public class Piece {
private int loc;
private int value;
/**
* Creates a new piece with a specified location and value.
*
* @precondition loc >= 0 & newLoc <= 8
* & value >= 1 & value <= 8
* @postcondition the piece is created.
* @param loc
* @param value
*/
public Piece(int loc, int value) {
this.moveTo(loc);
this.value = value;
}
/**
* Moves the piece to a new location.
*
* @precondition newLoc >= 0 & newLoc <= 8
* @precondition location = newLoc
*
* @param newLoc the new location of the piece.
*/
public void moveTo(int newLoc) {
if (newLoc < 0 || newLoc > 8) {
throw new IllegalArgumentException("The new location is not valid.");
}
this.loc = newLoc;
}
/**
* Gets the location of the piece.
*
* @precondition None
* @postcondition None
*
* @return loc the location of the piece.
*/
public int getLoc() {
return this.loc;
}
/**
* Gets the value of the piece.
*
* @precondition None
* @postcondition None
*
* @return value the Value of the piece.
*/
public int getValue() {
return this.value;
}
} }