From c0050a6a3132080b5c144004b72ff5848a1523bf Mon Sep 17 00:00:00 2001 From: Trishaan Date: Sun, 28 Sep 2025 19:34:59 -0700 Subject: [PATCH] Added sting validator to Idevice --- src/code/ca/bcit/comp2522/lab03/IDevice.java | 9 +++++++++ src/code/ca/bcit/comp2522/lab03/IPad.java | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/code/ca/bcit/comp2522/lab03/IDevice.java b/src/code/ca/bcit/comp2522/lab03/IDevice.java index e1801ab..473de7f 100644 --- a/src/code/ca/bcit/comp2522/lab03/IDevice.java +++ b/src/code/ca/bcit/comp2522/lab03/IDevice.java @@ -53,6 +53,15 @@ public abstract class IDevice { return this.purpose; } + /** + * stringValidator checks if the string is within character + * bounds and if it is blank, null or empty. + * @param toBeValidated passes the string that needs to be validated. + * @param maxCharacterCount passes the maximum number of characters that can be accepted + * as an integer. + * @param minCharacterCount passes the minimum number of characters that can be accepted + * as an integer. + * */ public void stringValidator(String toBeValidated, int minCharacterCount, int maxCharacterCount) { if (toBeValidated == null) { throw new IllegalArgumentException("Value cannot be null"); diff --git a/src/code/ca/bcit/comp2522/lab03/IPad.java b/src/code/ca/bcit/comp2522/lab03/IPad.java index e8ea924..fad009d 100644 --- a/src/code/ca/bcit/comp2522/lab03/IPad.java +++ b/src/code/ca/bcit/comp2522/lab03/IPad.java @@ -11,6 +11,9 @@ package ca.bcit.comp2522.lab03; */ public class IPad extends IDevice { + private final int MAX_OSVERSION_CHARACTERS = 10; + private final int MIN_OSVERSION_CHARACTERS = 1; + private final boolean hasCase; private final String OSVersion; @@ -27,6 +30,9 @@ public class IPad extends IDevice { // TODO: validate String inputs this.hasCase = hasCase; + stringValidator(OSVersion, + MIN_OSVERSION_CHARACTERS, + MAX_OSVERSION_CHARACTERS); this.OSVersion = OSVersion; }