tidy lab03

This commit is contained in:
SowinskiBraeden committed 2025-09-29 14:07:32 -07:00
1 parent e77c04ee89
commit af69fe5caa
6 files changed
+114 -75

No files matched your search

+21 -11
View File
@@ -9,7 +9,9 @@ package ca.bcit.comp2522.lab03;
* @author Trishaan Shetty
* @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 +25,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,10 +67,12 @@ 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) {
@@ -77,9 +84,12 @@ public abstract class IDevice {
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) {
+24 -15
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 NO_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;
+13 -8
View File
@@ -9,13 +9,15 @@ 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;
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;
final int memoryGB;
/**
* IPhone16 constructor
@@ -51,7 +53,8 @@ public class IPhone16 extends IPhone {
* @return IPhone16 instance variables
*/
@Override
public String toString() {
public String toString()
{
final StringBuilder builder;
@@ -74,7 +77,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 +109,8 @@ public class IPhone16 extends IPhone {
* @return hash code of IPhone16
*/
@Override
public int hashCode() {
public int hashCode()
{
int hash;
@@ -127,7 +132,7 @@ public class IPhone16 extends IPhone {
public void memoryGBValidator(final int memoryGB)
throws IllegalArgumentException
{
if (memoryGB % BASE_VARIANT_MEMORY != IS_A_MULTIPLE_OF_BASE_VARIANT)
if (memoryGB % BASE_VARIANT_MEMORY_GB != IS_A_MULTIPLE_OF_BASE_VARIANT)
{
throw new IllegalArgumentException("Invalid Memory value (GB)");
}
+13 -8
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 NO_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;