From 6025d318ff74947e90486f5878de4749e2e98837 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Fri, 2 Feb 2024 18:44:35 -0500 Subject: [PATCH] Fixed Preconditions for Piece Constructor. --- src/Assignments/A1/models/Piece.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Assignments/A1/models/Piece.java b/src/Assignments/A1/models/Piece.java index ecdcc36..2932c1d 100644 --- a/src/Assignments/A1/models/Piece.java +++ b/src/Assignments/A1/models/Piece.java @@ -22,6 +22,9 @@ public class Piece { * @param value the value of the piece. (FINAL) */ public Piece(int loc, int value) { + if (value < 1 || value > 8) { + throw new IllegalArgumentException("The piece value is not valid. Valid Range: 1 <= Value <= 8"); + } this.moveTo(loc); this.value = value; @@ -37,7 +40,7 @@ public class Piece { */ public void moveTo(int newLoc) { if (newLoc < 0 || newLoc > 8) { - throw new IllegalArgumentException("The new location is not valid."); + throw new IllegalArgumentException("The new location is not valid. Valid Range: 0 <= Location <= 8."); } this.loc = newLoc; }