Added throws IllegalArgumentException to all required methods and made necessary variables final and static

This commit is contained in:
Trishaan committed 2025-09-29 13:51:22 -07:00
1 parent 0385837c0d
commit 02bc37b44f
5 files changed
+17 -11

No files matched your search

+5 -3
View File
@@ -10,8 +10,8 @@ package ca.bcit.comp2522.lab03;
* @version 1.0.0
*/
public abstract class IDevice {
private final int MIN_PURPOSE_CHARACTER = 1;
private final int MAX_PURPOSE_CHARACTER = 255;
private final static int MIN_PURPOSE_CHARACTER = 1;
private final static int MAX_PURPOSE_CHARACTER = 255;
private final String purpose;
@@ -20,7 +20,8 @@ public abstract class IDevice {
*
* @param purpose of IDevice
*/
public IDevice(final String purpose) {
public IDevice(final String purpose)
{
stringValidator(purpose,
MIN_PURPOSE_CHARACTER,
@@ -64,6 +65,7 @@ public abstract class IDevice {
public void stringValidator(final String toBeValidated,
final int minCharacterCount,
final int maxCharacterCount)
throws IllegalArgumentException
{
if (toBeValidated == null) {
+2 -2
View File
@@ -11,8 +11,8 @@ 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 static int MAX_OSVERSION_CHARACTERS = 10;
private final static int MIN_OSVERSION_CHARACTERS = 1;
private final boolean hasCase;
private final String OSVersion;
@@ -129,6 +129,7 @@ public class IPhone extends IDevice {
}
public void minutesValidator(final double mins)
throws IllegalArgumentException
{
if(mins < NO_MINUTES_REMAINING)
{
@@ -12,6 +12,7 @@ package ca.bcit.comp2522.lab03;
public class IPhone16 extends IPhone {
private static final int BASE_VARIANT_MEMORY = 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;
@@ -24,10 +25,10 @@ public class IPhone16 extends IPhone {
* @param memoryGB of this IPhone
*/
public IPhone16(
final double remainingPhonePlanMinutes,
final String carrier,
final double remainingPhonePlanMinutes,
final String carrier,
final boolean highResolutionCamera,
final int memoryGB
final int memoryGB
) {
super(remainingPhonePlanMinutes, carrier);
@@ -123,9 +124,10 @@ public class IPhone16 extends IPhone {
* since it needs to be a multiple of 128.
* @param memoryGB passes the value of the memory to the method.
* */
public void memoryGBValidator(int memoryGB)
public void memoryGBValidator(final int memoryGB)
throws IllegalArgumentException
{
if (memoryGB % BASE_VARIANT_MEMORY != 0)
if (memoryGB % BASE_VARIANT_MEMORY != IS_A_MULTIPLE_OF_BASE_VARIANT)
{
throw new IllegalArgumentException("Invalid Memory value (GB)");
}
+2 -1
View File
@@ -129,7 +129,8 @@ public class IPod extends IDevice {
* passed are not negative.
* @param songNumber passes the value of the number of songs.
* */
public void numberOfSongsValidator(int songNumber)
public void numberOfSongsValidator(final int songNumber)
throws IllegalArgumentException
{
if(songNumber < NO_SONGS)
{