merge main into braeden/lab04

This commit is contained in:
SowinskiBraeden committed 2025-10-03 20:46:59 -07:00
commit b5a9c79b83
6 files changed
+227 -76

No files matched your search

+25 -11
View File
@@ -7,9 +7,12 @@ 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 {
public abstract class IDevice
{
private final static int MIN_PURPOSE_CHARACTER = 1;
private final static int MAX_PURPOSE_CHARACTER = 255;
@@ -23,9 +26,12 @@ public abstract class IDevice {
public IDevice(final String purpose)
{
stringValidator(purpose,
MIN_PURPOSE_CHARACTER,
MAX_PURPOSE_CHARACTER);
stringValidator(
purpose,
MIN_PURPOSE_CHARACTER,
MAX_PURPOSE_CHARACTER
);
this.purpose = purpose;
}
@@ -62,24 +68,32 @@ public abstract class IDevice {
* @param minCharacterCount passes the minimum number of characters that can be accepted
* as an integer.
* */
public void stringValidator(final String toBeValidated,
final int minCharacterCount,
final int maxCharacterCount)
throws IllegalArgumentException
public void stringValidator(
final String toBeValidated,
final int minCharacterCount,
final int maxCharacterCount
)
throws IllegalArgumentException
{
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) {
throw new IllegalArgumentException("Value length must be between"
+ minCharacterCount + "and " + maxCharacterCount + " characters");
if (toBeValidated.length() < minCharacterCount ||
toBeValidated.length() > maxCharacterCount
)
{
throw new IllegalArgumentException("Value length must be between" +
minCharacterCount + "and " + maxCharacterCount + " characters");
}
}
}
+20 -11
View File
@@ -9,13 +9,14 @@ package ca.bcit.comp2522.lab03;
* @author Trishaan Shetty
* @version 1.0.0
*/
public class IPad extends IDevice {
public class IPad extends IDevice
{
private final static int MAX_OSVERSION_CHARACTERS = 10;
private final static int MIN_OSVERSION_CHARACTERS = 1;
private final static int MAX_OS_VERSION_CHARACTERS = 25;
private final static int MIN_OS_VERSION_CHARACTERS = 1;
private final boolean hasCase;
private final String OSVersion;
private final String OSVersion;
/**
* IPad constructor
@@ -24,13 +25,18 @@ public class IPad extends IDevice {
*/
public IPad(
final boolean hasCase,
final String OSVersion
final String OSVersion
) {
super("learning");
this.hasCase = hasCase;
stringValidator(OSVersion,
MIN_OSVERSION_CHARACTERS,
MAX_OSVERSION_CHARACTERS);
stringValidator(
OSVersion,
MIN_OS_VERSION_CHARACTERS,
MAX_OS_VERSION_CHARACTERS
);
this.OSVersion = OSVersion;
}
@@ -46,7 +52,8 @@ public class IPad extends IDevice {
* printDetails of IPad including if it has a case
* and which operating system version it is running
*/
public void printDetails() {
public void printDetails()
{
final StringBuilder details;
@@ -66,7 +73,8 @@ public class IPad extends IDevice {
* @return IPad instance variables
*/
@Override
public String toString() {
public String toString()
{
final StringBuilder details;
@@ -89,7 +97,8 @@ public class IPad extends IDevice {
* @return if the IPads have the same OS Version
*/
@Override
public boolean equals(final Object o) {
public boolean equals(final Object o)
{
// Ensure object exists
if (o == null) {
+33 -20
View File
@@ -9,12 +9,14 @@ package ca.bcit.comp2522.lab03;
* @author Trishaan Shetty
* @version 1.0.0
*/
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 int IPHONE_HASH = 11;
private static final int IPHONE_HASH_CODE = 101;
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 MIN_MINUTES_REMAINING = 0.0;
private static final int IPHONE_HASH = 11;
private static final int IPHONE_HASH_CODE = 101;
private final double remainingPhonePlanMinutes;
private final String carrier;
@@ -26,16 +28,19 @@ public class IPhone extends IDevice {
*/
public IPhone(
final double remainingPhonePlanMinutes,
final String carrier)
{
final String carrier
) {
super("talking");
minutesValidator(remainingPhonePlanMinutes);
this.remainingPhonePlanMinutes = remainingPhonePlanMinutes;
stringValidator(carrier,
MIN_CAREER_CHARACTERS,
MAX_CAREER_CHARACTERS);
stringValidator(
carrier,
MIN_CAREER_CHARACTERS,
MAX_CAREER_CHARACTERS
);
this.carrier = carrier;
}
@@ -51,7 +56,8 @@ public class IPhone extends IDevice {
* printDetails of IPhone including carrier and remaining
* phone plan minutes
*/
public void printDetails() {
public void printDetails()
{
final StringBuilder details;
@@ -71,7 +77,8 @@ public class IPhone extends IDevice {
* @return IPhone instance variables
*/
@Override
public String toString() {
public String toString()
{
final StringBuilder iphoneDetails;
@@ -93,7 +100,8 @@ public class IPhone extends IDevice {
* @return if the IPhone has the same remaining phone plan minutes
*/
@Override
public boolean equals(final Object o) {
public boolean equals(final Object o)
{
// Ensure object exists
if (o == null) {
@@ -118,7 +126,8 @@ public class IPhone extends IDevice {
* @return hash code of IPhone
*/
@Override
public int hashCode() {
public int hashCode()
{
int hash;
@@ -128,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");
}
}
}
+11 -23
View File
@@ -9,13 +9,13 @@ package ca.bcit.comp2522.lab03;
* @author Trishaan Shetty
* @version 1.0.0
*/
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;
public class IPhone16 extends IPhone
{
private static final int IPHONE_HASH_WITH_HIGH_RES = 103;
final boolean highResolutionCamera;
final int memoryGB;
final int memoryGB;
/**
* IPhone16 constructor
@@ -34,7 +34,6 @@ public class IPhone16 extends IPhone {
this.highResolutionCamera = highResolutionCamera;
memoryGBValidator(memoryGB);
this.memoryGB = memoryGB;
}
@@ -51,7 +50,8 @@ public class IPhone16 extends IPhone {
* @return IPhone16 instance variables
*/
@Override
public String toString() {
public String toString()
{
final StringBuilder builder;
@@ -74,7 +74,8 @@ public class IPhone16 extends IPhone {
* @return if the IPhone has the same remaining phone plan minutes and high resolution camera
*/
@Override
public boolean equals(final Object o) {
public boolean equals(final Object o)
{
// Ensure object exists
if (o == null) {
@@ -105,7 +106,8 @@ public class IPhone16 extends IPhone {
* @return hash code of IPhone16
*/
@Override
public int hashCode() {
public int hashCode()
{
int hash;
@@ -118,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 != IS_A_MULTIPLE_OF_BASE_VARIANT)
{
throw new IllegalArgumentException("Invalid Memory value (GB)");
}
}
}
+15 -11
View File
@@ -9,13 +9,14 @@ package ca.bcit.comp2522.lab03;
* @author Trishaan Shetty
* @version 1.0.0
*/
public class IPod extends IDevice {
public class IPod extends IDevice
{
private static final int NO_SONGS = 0;
private static final int IPOD_HASH = 7;
private static final int MIN_SONGS = 0;
private static final int IPOD_HASH = 7;
private static final int IPOD_HASH_CODE = 97;
private final int numberOfSongs;
private final int numberOfSongs;
private final double maxVolumeDecibels;
/**
@@ -39,7 +40,8 @@ public class IPod extends IDevice {
* printDetails of IPod including number of songs
* and max volume in decibels.
*/
public void printDetails() {
public void printDetails()
{
final StringBuilder details;
@@ -67,7 +69,8 @@ public class IPod extends IDevice {
* @return IPod instance variables
*/
@Override
public String toString() {
public String toString()
{
final StringBuilder ipodDetails;
@@ -89,7 +92,8 @@ public class IPod extends IDevice {
* @return if the IPods have the same number of songs
*/
@Override
public boolean equals(final Object o) {
public boolean equals(final Object o)
{
// Ensure object exists
if (o == null) {
@@ -114,7 +118,8 @@ public class IPod extends IDevice {
* @return hash code of IPod
*/
@Override
public int hashCode() {
public int hashCode()
{
int hash;
@@ -130,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);
}
}
}