From a2d3c94198d1e2b1d51ccc7b704b36eee9c9a5a2 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Mon, 29 Sep 2025 14:17:52 -0700 Subject: [PATCH] fix lab03 --- .idea/workspace.xml | 5 +---- src/code/ca/bcit/comp2522/lab03/IDevice.java | 4 ++++ src/code/ca/bcit/comp2522/lab03/IPhone.java | 16 ++++++++++------ src/code/ca/bcit/comp2522/lab03/IPhone16.java | 17 ----------------- src/code/ca/bcit/comp2522/lab03/IPod.java | 7 +++---- 5 files changed, 18 insertions(+), 31 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 730bbed..0d5f0d2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,12 +5,9 @@ - - - diff --git a/src/code/ca/bcit/comp2522/lab03/IDevice.java b/src/code/ca/bcit/comp2522/lab03/IDevice.java index 69dd990..1e92bd8 100644 --- a/src/code/ca/bcit/comp2522/lab03/IDevice.java +++ b/src/code/ca/bcit/comp2522/lab03/IDevice.java @@ -7,6 +7,7 @@ package ca.bcit.comp2522.lab03; * @author Braeden Sowinski * @author Nicolas Agostini * @author Trishaan Shetty + * * @author Calvin Arifianto * @version 1.0.0 */ public abstract class IDevice @@ -78,12 +79,15 @@ public abstract class IDevice if (toBeValidated == null) { throw new IllegalArgumentException("Value cannot be null"); } + if (toBeValidated.isEmpty()) { throw new IllegalArgumentException("Value cannot be empty"); } + if (toBeValidated.isBlank()) { throw new IllegalArgumentException("Value cannot be blank"); } + if (toBeValidated.length() < minCharacterCount || toBeValidated.length() > maxCharacterCount ) diff --git a/src/code/ca/bcit/comp2522/lab03/IPhone.java b/src/code/ca/bcit/comp2522/lab03/IPhone.java index 5e74661..2c0133e 100644 --- a/src/code/ca/bcit/comp2522/lab03/IPhone.java +++ b/src/code/ca/bcit/comp2522/lab03/IPhone.java @@ -14,7 +14,7 @@ public class IPhone extends IDevice private static final int MIN_CAREER_CHARACTERS = 3; private static final int MAX_CAREER_CHARACTERS = 15; - private static final double NO_MINUTES_REMAINING = 0.0; + private static final double MIN_MINUTES_REMAINING = 0.0; private static final int IPHONE_HASH = 11; private static final int IPHONE_HASH_CODE = 101; @@ -137,13 +137,17 @@ public class IPhone extends IDevice } - public void minutesValidator(final double mins) - throws IllegalArgumentException + /** + * minutesValidator ensures that a given number of minutes + * is not less than the minimum. + * @param mins to verify + */ + public static void minutesValidator(final double mins) { - if(mins < NO_MINUTES_REMAINING) + if(mins < MIN_MINUTES_REMAINING) { - throw new IllegalArgumentException("Minutes cannot be negative"); + throw new IllegalArgumentException("Minutes cannot be less than " + + MIN_MINUTES_REMAINING + " minutes"); } - } } diff --git a/src/code/ca/bcit/comp2522/lab03/IPhone16.java b/src/code/ca/bcit/comp2522/lab03/IPhone16.java index d708e3e..1fbe512 100644 --- a/src/code/ca/bcit/comp2522/lab03/IPhone16.java +++ b/src/code/ca/bcit/comp2522/lab03/IPhone16.java @@ -12,9 +12,7 @@ package ca.bcit.comp2522.lab03; public class IPhone16 extends IPhone { - private static final int BASE_VARIANT_MEMORY_GB = 128; private static final int IPHONE_HASH_WITH_HIGH_RES = 103; - private static final int IS_A_MULTIPLE_OF_BASE_VARIANT = 0; final boolean highResolutionCamera; final int memoryGB; @@ -36,7 +34,6 @@ public class IPhone16 extends IPhone this.highResolutionCamera = highResolutionCamera; - memoryGBValidator(memoryGB); this.memoryGB = memoryGB; } @@ -123,18 +120,4 @@ public class IPhone16 extends IPhone return hash; } - - /** - * memoryGBValidator makes sure the right memory storage is assigned - * since it needs to be a multiple of 128. - * @param memoryGB passes the value of the memory to the method. - * */ - public void memoryGBValidator(final int memoryGB) - throws IllegalArgumentException - { - if (memoryGB % BASE_VARIANT_MEMORY_GB != IS_A_MULTIPLE_OF_BASE_VARIANT) - { - throw new IllegalArgumentException("Invalid Memory value (GB)"); - } - } } diff --git a/src/code/ca/bcit/comp2522/lab03/IPod.java b/src/code/ca/bcit/comp2522/lab03/IPod.java index 6cb3f8b..4723ea1 100644 --- a/src/code/ca/bcit/comp2522/lab03/IPod.java +++ b/src/code/ca/bcit/comp2522/lab03/IPod.java @@ -12,7 +12,7 @@ package ca.bcit.comp2522.lab03; public class IPod extends IDevice { - private static final int NO_SONGS = 0; + private static final int MIN_SONGS = 0; private static final int IPOD_HASH = 7; private static final int IPOD_HASH_CODE = 97; @@ -135,11 +135,10 @@ public class IPod extends IDevice * @param songNumber passes the value of the number of songs. * */ public void numberOfSongsValidator(final int songNumber) - throws IllegalArgumentException { - if(songNumber < NO_SONGS) + if(songNumber < MIN_SONGS) { - throw new IllegalArgumentException("Number of songs cannot be less than 0"); + throw new IllegalArgumentException("Number of songs cannot be less than " + MIN_SONGS); } } }